The Linux system can be a confusing place for someone new to Linux. So we decided to steal some tips from our Linux guru’s at Host Africa. The following basics will help you manage:
A useful command to use to find out where you currently are is pwd. This command, like a lot of Linux commands, is an abbreviation for Present Working Directory. This command tells you exactly that.
$:~# pwd /usr/local/sbin
Next, we can find out what is at this location with the ls command. The is short for list. ls has several switches to modify the output such as ls -l – the -l is for long.
$:~# ls checkPPAs ipsec limitmem nvpn svpn svpn~ swanctl uninstall_urbackupclient urbackupclientbackend $:~# ls -l total 3136 -rwxr-xr-x 1 root root 1322 Jan 7 10:33 checkPPAs -rwxr-xr-x 1 root root 7504 Apr 6 2016 ipsec -rwxr-xr-x 1 root root 1214 Dec 16 15:31 limitmem -rwxr-xr-x 1 root root 74 Feb 22 19:11 nvpn -rwxr-xr-x 1 root root 154 Apr 9 07:55 svpn -rwxr-xr-x 1 root root 146 Mar 24 16:40 svpn~ -rwxr-xr-x 1 root root 429840 Apr 6 2016 swanctl -rwxr-xr-x 1 root root 2924 May 25 2017 uninstall_urbackupclient -rwxr-xr-x 1 root root 2747688 May 25 2017 urbackupclientbackend
Switches and shortcuts
Some other very useful switches are -a for all and -t for time (sort by). ls -a will show you any hidden or special files. Note that every directory has 2 special files which are used for navigation and should never be attempted to delete. These are “.” and “..” (dot and dot dot). The single dot represents the current directory and the double dot represents the next level up. Thus typing in cd .. (change directory and move one level up) gets you one level up. Running an executable that has the x bit set with chmod +x in the same directory is done with ./executable .sh.
Another often forgotten navigation aid is the tilde (~). This helps you move to the home directory of the current user. Once again, we simply add it to the cd command with cd ~ (that is cd space tilde).
TIP: If you run the command cd without any arguments then it will always take you back to your home directory.
Using the cd command, we can move in one of two ways. By ABSOLUTE PATH ( always RELATIVE to SYSTEM ROOT, which is / ) or by RELATIVE PATH ( always RELATIVE to CURRENT DIRECTORY ). So to move to joe’s home directory from /home we could use the ABSOLUTE ” cd /home/joe “ or we could use ” cd joe “. For absolute accuracy, you could use ” cd ./joe “, but this is not really necessary.
TIP: Tab Completion
Typing out these paths can become tedious. I am often prone to making typos. The command line has a nice little mechanism to help us in this respect. It’s called Tab Completion. When you start typing a path (anywhere on the command line, you’re not just limited to certain commands) you may hit the Tab key on your keyboard at any time which will invoke an autocomplete action. If nothing happens then that means there are several possibilities. If you hit Tab again it will show you those possibilities. You may then continue typing and hit Tab again and it will again try to autocomplete for you.
It’s best if you try it yourself. If you start typing ” cd /hoTab/<beginning of your username>Tab ” you’ll get a feel for how it works.