Terminal

Published:

Using command-line interface is important as most of the development tools are run through terminals and not many have GUIs. You will have to learn individual tools separately such as git, ssh and docker but some conventions apply.

In my opinion, it is necessary to remember only the basic commands listed at [3]. The other depends on situation and I think those should be collected to a cheatsheet. They will be memorized through frequent use.

In Ubuntu, we have a shortcut for opening a terminal CTRL + ALT + T. I recommend setting one as well if not already.

Navigation and File Listing

You can access the file-system via terminal. Usually you want to run commands inside a certain directory such as project directory.

The terminal usually shows the current folder before a delimiter such as $ or >.

/home/laychdev$

It seems a popular convention to use dollar-sign whenever a command-line snippet is shown. But do not copy to dollar-sign!

To change directory we use the following basic commands

# Navigate to any directory
$ cd {directory_path}

# To home folder.
$ cd

# To one directory up.
$ cd ..

Another related command is directory listing, so that files in a directory is shown.

# Shows current directory contents, doesn't show hidden files.
$ ls

# Shows all files in current directory including hidden ones.
$ ls -a

# Shows more information about files such as permissions.
$ ls -l

# Shows contents of a given directory
$ ls {directory_location}

Files and Directories

Another useful tool is to make and remove directories.

# Make directory (create).
$ mkdir {directory_path}

# Copy directory
$ cp -r {source_directory_path} {destination_path}

# Move directory
$ mv -r {source_directory_path} {destination_path}

# Remove directory
$ rm -r {directory_path}

To create files, I prefer just opening nano -command-line text-editor and saving the file. The files usually need contents anyway.

# These are equivalents for files.
$ cp {source_file_path} {destination}
$ mv {source_file_path} {destination}
$ rm {file_path}

Setting Permissions

Sometimes the file should belong to a different user such root but was created by another user. We can change the ownership with chown.

# Change Ownership
$ chown {new_owner} {file or directory}
$ chown :{new_owner_group} {file or directory}

If only permission change is needed, we use chmod.

# Add a permission to user owning the resource.
$ chmod u+{permissions} {file or directory}

# Add permissions to group.
$ chmod g+{permissions} {file or directory}

# Add public permission to others (public).
$ chmod o+{permissions} {file or directory}

# Add to all
$ chmod a+{permissions} {file or directory}

Where permissions are is a substring of rwx. To remove permission, replace + with -.

Other Commands

Other commands that requires installation depends on the developers of those application, so they will be discussed in other articles.

References

  1. https://en.wikipedia.org/wiki/Cd_(command)
  2. https://en.wikipedia.org/wiki/Ls
  3. https://wiki.archlinux.org/index.php/Core_utilities#Essentials
  4. https://wiki.archlinux.org/index.php/File_permissions_and_attributes#Changing_ownership
  5. https://www.gnu.org/software/coreutils/manual/html_node/chown-invocation.html
  6. https://wiki.archlinux.org/index.php/File_permissions_and_attributes#Changing_permissions