In this tutorial, you'll learn the most common and useful commands that you can run in almost any UNIX-like environment, including Linux and Mac OS X. - print working directory pwd allows you to output the current directory you’re in. It provides a short and easy answer to the question "Where am I?" It’s very useful to run the command at the beginning of your terminal session. Here’s an example of running right after logging into the server as a root. pwd pwd pwd root@scw-tender-lewin:~ /root # pwd - list files and directories ls To view the content of the directory, you can use the ( ) command. The basic usage goes like this: ls list root@scw-tender-lewin:/ bin dev home initrd.img.old lib64 media opt root sbin srv sys usr vmlinuz boot etc initrd.img lib lost+found mnt proc run snap swapfile tmp var vmlinuz.old # ls If you want to check out the content of a specific directory, i.e. var, you can do it by adding its path right after the : ls root@scw-tender-lewin:/ backups cache crash lib lock mail opt run snap spool tmp # ls /var local log There are also a couple of useful flags that will change the format of the output of the command. ls Long list view The flag will do the long list view, which shows additional information like permissions, owner, size, date, etc.: -l root@scw-tender-lewin:/ total 4194396 drwxr-xr-x 2 root root 4096 May 15 06:46 bin drwxr-xr-x 4 root root 4096 Sep 3 06:15 boot drwxr-xr-x 16 root root 3680 May 20 06:35 dev drwxrwxr-x 93 root root 4096 Sep 3 06:15 etc drwxr-xr-x 3 root root 4096 Mar 6 09:14 home lrwxrwxrwx 1 root root 34 Sep 3 06:15 initrd.img -> boot/initrd.img-4.15.0-115-generic lrwxrwxrwx 1 root root 34 Sep 3 06:15 initrd.img.old -> boot/initrd.img-4.15.0-112-generic drwxr-xr-x 23 root root 4096 Mar 6 09:16 lib drwxr-xr-x 2 root root 4096 Jul 8 06:20 lib64 drwx------ 2 root root 16384 Mar 5 2019 lost+found drwxr-xr-x 2 root root 4096 Feb 4 2019 media drwxr-xr-x 2 root root 4096 Feb 4 2019 mnt drwxr-xr-x 3 root root 4096 Mar 6 09:17 opt dr-xr-xr-x 189 root root 0 May 4 06:16 proc drwx------ 8 root root 4096 Mar 19 08:13 root drwxr-xr-x 28 root root 1120 Sep 3 07:21 run drwxr-xr-x 2 root root 12288 Jul 8 06:20 sbin drwxr-xr-x 2 root root 4096 Mar 6 09:14 snap drwxr-xr-x 2 root root 4096 Feb 4 2019 srv -rw------- 1 root root 4294967296 Mar 6 10:10 swapfile dr-xr-xr-x 13 root root 0 May 4 06:16 sys drwxrwxrwt 10 root root 4096 Sep 3 07:22 tmp drwxrwxr-x 10 root root 4096 Mar 5 2019 usr drwxr-xr-x 13 root root 4096 Mar 5 2019 var lrwxrwxrwx 1 root root 31 Sep 3 06:15 vmlinuz -> boot/vmlinuz-4.15.0-115-generic lrwxrwxrwx 1 root root 31 Sep 3 06:15 vmlinuz.old -> boot/vmlinuz-4.15.0-112-generic # ls -l By the way, if you want to check some specific information about a single file, you can add its name the same way we did with the directory. Here’s how you could check the long list view on the : swapfile root@scw-tender-lewin:/ -rw------- 1 root root 4294967296 Mar 6 10:10 swapfile # ls -l swapfile Hidden files and folders To view the hidden files and folders you should add the flag to the command: -a ls root@scw-tender-lewin:/ . bin dev home initrd.img.old lib64 media opt root sbin srv sys usr vmlinuz .. boot etc initrd.img lib lost+found mnt proc run snap swapfile tmp var vmlinuz.old # ls -a This way, we always get at least two additional records: and . A single dot stands for the current directory and the double dot is used to access the directory one level above the current. . .. Sorting the output of the command ls The flag is used to sort the results by size in descending order. -S root@scw-tender-lewin:/ swapfile sbin boot home lib64 mnt root srv usr dev initrd.img vmlinuz proc lost+found bin etc lib media opt snap tmp var run initrd.img.old vmlinuz.old sys # ls -S Combining the flags Quite often you want to achieve a complex behavior. For example, you might want to get both the long list view with , the human-readable size output with and sort the results with the flag. -l -h -S To achieve this, you can just combine all flags into one. The order of the flags doesn’t matter here and is equivalent to , so you can use any sequence you like: -lhS -hSl root@scw-tender-lewin:/ total 4.1G -rw------- 1 root root 4.0G Mar 6 10:10 swapfile drwx------ 2 root root 16K Mar 5 2019 lost+found drwxr-xr-x 2 root root 12K Jul 8 06:20 sbin drwxr-xr-x 23 root root 4.0K Sep 3 06:15 . drwxr-xr-x 23 root root 4.0K Sep 3 06:15 .. drwxr-xr-x 2 root root 4.0K May 15 06:46 bin drwxr-xr-x 4 root root 4.0K Sep 3 06:15 boot drwxrwxr-x 93 root root 4.0K Sep 3 06:15 etc drwxr-xr-x 3 root root 4.0K Mar 6 09:14 home drwxr-xr-x 23 root root 4.0K Mar 6 09:16 lib drwxr-xr-x 2 root root 4.0K Jul 8 06:20 lib64 drwxr-xr-x 2 root root 4.0K Feb 4 2019 media drwxr-xr-x 2 root root 4.0K Feb 4 2019 mnt drwxr-xr-x 3 root root 4.0K Mar 6 09:17 opt drwx------ 8 root root 4.0K Mar 19 08:13 root drwxr-xr-x 2 root root 4.0K Mar 6 09:14 snap drwxr-xr-x 2 root root 4.0K Feb 4 2019 srv drwxrwxrwt 10 root root 4.0K Sep 3 07:22 tmp drwxrwxr-x 10 root root 4.0K Mar 5 2019 usr drwxr-xr-x 13 root root 4.0K Mar 5 2019 var drwxr-xr-x 16 root root 3.6K May 20 06:35 dev drwxr-xr-x 28 root root 1.1K Sep 3 07:21 run lrwxrwxrwx 1 root root 34 Sep 3 06:15 initrd.img -> boot/initrd.img-4.15.0-115-generic lrwxrwxrwx 1 root root 34 Sep 3 06:15 initrd.img.old -> boot/initrd.img-4.15.0-112-generic lrwxrwxrwx 1 root root 31 Sep 3 06:15 vmlinuz -> boot/vmlinuz-4.15.0-115-generic lrwxrwxrwx 1 root root 31 Sep 3 06:15 vmlinuz.old -> boot/vmlinuz-4.15.0-112-generic dr-xr-xr-x 191 root root 0 May 4 06:16 proc dr-xr-xr-x 13 root root 0 Sep 3 08:25 sys # ls -lhS - change directory cd So, after you’ve learned everything about the content in the directory, you probably want to go somewhere else. The command will take a directory name as a single argument and move you there. The command only prints the output if there’s an error, so you might want to immediately use the command to look around: cd cd ls root@scw-tender-lewin:/ root@scw-tender-lewin:/var . .. backups cache crash lib lock mail opt run snap spool tmp # cd var # ls -a local log Moving into the parent folder To move one folder above you should use the as a directory name. To move two or more levels above you can type and so on. .. cd ../.. If you’ve tried to navigate to the directory that doesn’t exist, you’ll see the following message: root@scw-tender-lewin:/var -bash: : local42: No such file or directory root@scw-tender-lewin:/var root@scw-tender-lewin:/ bin dev home initrd.img.old lib64 media opt root sbin srv sys usr vmlinuz boot etc initrd.img lib lost+found mnt proc run snap swapfile tmp var vmlinuz.old # cd local42 cd # cd .. # ls Going home If you use the symbol as a directory name, you’ll be moved into your home folder. It’s a useful shortcut as it doesn’t matter where you are at the moment and you might now know the exact path to the home directory at some point. ~ root@scw-tender-lewin:/ root@scw-tender-lewin:~ /root # cd ~ # pwd - create a file touch The command allows you to create an empty file. So, here’s the plan: touch Navigate to our home directory with cd ~ Make sure it’s empty with ls Create a new file using and providing a filename right after it touch Run the command once again to see that the newly created file exists ls root@scw-tender-lewin:/var/ root@scw-tender-lewin:~ root@scw-tender-lewin:~ root@scw-tender-lewin:~ hello.txt log # cd ~ # ls # touch hello.txt # ls - create a directory mkdir To create a directory in Linux you should use the command. It works almost the same way as and expects the directory name. mkdir touch root@scw-tender-lewin:~ root@scw-tender-lewin:~ hello.txt internal # mkdir internal # ls - display a manual / get help man And finally, the superpower! The command will give you a short manual on any command, even itself. If you want to do something but have forgotten an important flag or the command syntax, just type followed by the command name to get an instant manual. Here’s an example: man man root@scw-tender-lewin:~ NAME ls -- list directory contents SYNOPSIS ls [-ABCFGHLOPRSTUW@abcdefghiklmnopqrstuwx1%] [file ...] DESCRIPTION For each operand that names a file of a other than directory, ls displays its name as well as any requested, associated information. For each operand that names a file of directory, ls displays the names of files contained within that directory, as well as any requested, associated information. If no operands are given, the contents of the current directory are displayed. If more than one operand is given, non-directory operands are displayed first; directory and non-directory operands are sorted separately and lexicographical order. The following options are available: ... # man ls type type in Conclusion In this article, we’ve reviewed the easiest to use and straightforward Linux, macOS, and *nix system commands like , , , , , and . ls pwd cd touch mkdir man If you're just starting your journey into the software development world, you might be intimidated by the looks of the all-mighty terminal or command-line. But as you see, it's quite easy and straightforward if you start at the right spot. Thanks for reading! I write a programming blog at and teach JavaScript programming . learn.coderslang.com Full Stack JS course Talk soon! Previously published at https://learn.coderslang.com/0001-the-most-useful-terminal-commands-linux-mac-and-unix/