Get to know the Linux command line with these common tasks.
Your first step should be to familiarise yourself with the new interface, file system and other aspects of how the operating system works – but then we’d advise coming to grips with the Linux command line.
Graphic user interfaces (GUIs) in the Linux world have improved enormously – and one advantage to the open source OS is that if you don’t like one GUI, you can often try another. But while it’s feasible to use Linux without touching the command line, there are good reasons to learn it.
Typing in a command can be quicker than delving through menus – and if you take it further and learn scripting, you’ll be able to perform quite complex tasks very rapidly. Also, the command line versions of some applications are more powerful than the GUI versions.
You might see references to ‘the shell’, ‘bash’ or a ‘Terminal’ in relation to the command line. Each has a specific meaning which we won’t get into here. But essentially, to get to the command line, you’ll need to launch a Terminal – see your Linux distribution’s website if you’re not sure how to do that.
Now you’re ready to try these commonly used commands, which will enable you to perform tasks such as view file listings in a folder, add new files and folders and delete them again.
The first command you’ll need to know if you fancy yourself as a Linux whizz is the ‘ls’ command. This represents the list command and will present to you all items in a given file system. For example, typing ls/applications into the Linux terminal will present you with a list of all the applications installed in your applications folder. Type in ls followed by / and any folder on your device to see what’s in each folder or directory.
cd is the change directory and typing this command into the Linux terminal will allow you to switch from the current directory you’re working in to another. To use the command, type in cd followed by the /, then the directory you want to go to, including the entire pathname.
If you want to head straight to the home directory, you can simply input cd ~ to be taken straight to the home directory.
mv is the command for move and using this line instructs the system to move files from one directory to another. The first string of commands will locate the file to be moved, while the second will instruct Linux where to move it to.
An example would be: mv/mydoc/documents /mydoc/work which would move the mydoc file from the documents folder to the work folder.
If you want to create a new directory, use the mkdir command. Just type in mkdir followed by the new directory name, for example mkdir newdirectory and the newdirectory will be created on your Linux device.
As you’ve probably guessed, rmdir tells the Linux system to remove a particular directory. Just like mkdir, you simply have to type in rmdir with the directory name, for example rmdir newdirectory and newdirectory will be removed from the system.
You will not be able to delete any directories with files or other directories in it. To do this, you will need to remove the files or sub-directories first.
To remove files, you’ll need to use the rm command, followed by the file name. If you want to remove a directory with files in it, type in rm followed by the directory name.
Touch is the command for making new files within directories. To make use of the touch command, simply type in touch docname.extension to create that file type in the current directory. For example, touch textfile.txt will create an empty text file named textfile.
locate will help you find files and directories wherever they may be on your Linux system. This is where the command lines start to get a little complicated, because there are a number of parameters you can implement to find a specific file, or one containing any number of words, in upper or lower case.
The easiest (but unfortunately, laziest) way of locating a file is by using locate followed by -i, which tells the system to search using either upper or lower case and then the words you’re looking for with and asterisk before and after each word.
For example, if you’re looking for a file that contains the words “accounts 2016 2017”, you would type in locate -i *accounts**2016**2017 and up will pop a list of the files with matching words.
Had enough of a messy command line interface? Just type in clear and everything will magically disappear, allowing you to start with a clean slate again.