Simple Linux Navigation Commands
Posted 12 months ago at 8:38 pm. 0 comments
In this post I will show you a few must know commands to get started in linux/unix/Mac OS using the command line. The command line can be more useful than you may think. The first command you should know is ls. Now, ls is the most basic of commands, but for those of you just getting started its a very important one. What it does is list files inside a directory. For example, to view the files and directories within your home folder just open up the terminal and type ls. That it? Yup! Simple as pie. There are a few common options you can use with ls. -l brings up things like permissions, owner, group, time modified, etc… Try it by typing in ls -l. But you notice that the file size is an insanely large number. -h will fix that. Instead of bytes, it will show things in K(b), M, G when possible. But what if you have a bunch of hidden files and folders and want to see ‘em all at once? the -a option. So to call ls with multiple options, all you have to do is ls -lha.
Cool, you may be wondering. But how do you change directories? Easy! cd. Use cd to change to a directory relative to where you are already, or an absolute path. For example, say you are at your home directory (/home/myusername) and want to get to /var/log you can do either:
cd ../../var/log
cd /var/log
Clearly, typing cd /var/log is easier in this case, but what if you wanted to get to your “Desktop” Folder inside your home directory? Just cd Desktop. Note that you don’t have a ‘/’ in front of ‘Desktop’ because that would be saying that the Desktop directory is in your root. Also another trick is just cd, without a path or cd ~ will bring you to your home directory.
One last tip! you can click your tab key at any time while typing in a file path to auto-complete it. You can type in cd De and then press tab. If there are more than one matches though you will have to double click tab and it will list all of the possibilities. This is definitely a huge time saver.
Have fun out there!