Top 10 system tips
Make good use of the Terminal with this collection of commands.
From using the Terminal to explore the filesystem, to finding out more about the status of your hardware, becoming familiar with these commands is a must.
1 Get help
There are three ways to get help in the Terminal: Know the name of the tool? Use the --help flag: $ ls --help
The whatis tool is another useful help-related command, providing you with a brief description of a fully formed command: $ whatis apt-get install vlc
This will describe the apt-get tool, the install argument and what package vlc is. Note, however, that whatis ignores any flags.
Finally, the Terminal also provides access to a full-blown online manual via the man utility. Start with man intro for a long and detailed introduction of the Terminal itself, and man man for advice on navigating the manual. Finally, pair it with a specific tool – for example, man apt-get – for a detailed description of that tool written by programmers.
2 Navigating the filesystem
Open the Terminal and you start within your home folder. Use the ls -l command to confirm this. If you’d like to view all hidden files and folders (basically filenames with a full stop at the beginning – such as .hidden.sh), use ls -a . You can also view the contents of sub-folders within the current folder too, using ls --recursive .
The cd command enables you to quickly move between directories. To move inside a sub-folder within the current folder, use cd <Dirname> (remember, folders and files are case sensitive with Linux). To go back up a level, use cd .. or cd ../.. to jump up two levels. To navigate to the root directory, use cd / or type cd ~ to go to your /Home directory.
Type cd /path/to/folder to jump directly to another folder using its exact path (or cd ~/Documents if it’s inside your Home folder). Finally, type cd - to go back to the previous directory you were in. If your folder path contains spaces – for example, a folder named Star Trek, then you need to encompass the entire path inside single quotation marks: $ cd ‘~\Videos\Star Trek’ Handily you can tap the tab key to auto-complete file names.
3 Copy, move and delete
Need to manipulate files within the Terminal? Start by familiarising yourself with the cp (copy) and mv (move) tools, which share the same syntax: $ cp -i source destination Both source and destination can be complete folder paths, or just use the filename if you’ve already navigated to the folder containing the original file, while the -i flag ensures you’ll receive a warning if you try to overwrite an existing file of the same name. For example: $ cp -i invoice.odt ~/Documents/Backup
If you want to rename the copied file, simply append it to the end of the destination: ~/Documents/Backup/invoicebackup.odt for example. Similarly, cp invoice.odt invoicebackup.odt will create a renamed duplicate of the file in the same folder. Substitute mv to move or rename a file. If you want to copy a folder, use the -r flag to show recursion, which means the folder and its contents will be copied or moved.
Delete individual files using rm , and empty folders can be removed with the rmdir command (add the -r flag to delete a folder and any existing contents):
$ rmdir -r ~/Documents/Backup Finally, create new folders using the mkdir foldername command (again full paths are supported), and use touch filename to create a new, empty file – for example, touch config.sys . When creating folders with spaces in the name, remember to surround them with single quotation marks or by using a backslash (called an escape) character (\) before the troublesome space, for example: ‘mkdir Star\ Trek’ .
4 Change permissions
Nautilus provides some tools for tweaking permissions, but it’s quicker to use the chmod tool using the following syntax: $ chmod 777 file The file is obviously the name of the file, and can also refer to a folder (if you want to set all the folder’s contents – including sub-directories – to the same permissions as the folder itself, add the -R flag like so: $ chmod -R 777 folder
The key element here is the number 777 (never use this for system files), which refers to the permissions you’re setting. 7 stands for rwx (so full access), and the first number refers to the file owner, the second to the file’s group and the third to ‘everyone else’, as outlined earlier in this feature.
Other numbers worth considering are 6 ( rw- , or read/ write but no execute), 5 ( r-x, or read and execute), and 4 ( r-- , or read-only). So, assign 644 to a folder or file and you’re giving the owner read and write access, but restricting all others to read-only access. Set 775 and you’re giving the owner and named group full access, while everyone else can read and execute the file. Before diving into permissions, read https://help.ubuntu.com/community/FilePermissions.
5 Change user and owner
If you want to change the owner or group of a selected file or folder, use the chown command. $ chown user file You can use chgrp to change the group of a file, using the same syntax ( chgrp group file ), or you can use chown to change both user and group with one command, like so: $ chown owner:group file
6 Run multiple commands together
There are three ways to run two or more commands together on a single line (enabling you to wander off and make a cuppa while your PC gets on with the job). If you only want the second command to run if the first completes successfully then use the && argument, like so: $ sudo apt-get update && sudo apt-get upgrade
If you wanted the second command to run only if the first command failed, then substitute || for &&. Finally, use a semicolon (;) to run the second command regardless of what happens with the first: $ sudo apt-get update ; sudo apt-get remove vlc
7 Editing with nano
One popular use for the Terminal is to edit configuration files. The best tool for the job is nano , which works just like a regular text editor. Invoke it thus: $ sudo nano /path/filename You’ll notice the Terminal change to the nano interface – the filename and path is listed at the top, and a list of basic commands are shown at the bottom – the ^ symbol refers to the [Ctrl] key.
Your file’s contents take up the main area of the nano interface – there’s no text wrapping, so look for $ symbols on the right indicating the line doesn’t fit (resize the window or press [End] to jump to the end of the line).
Use [Home]/[End] to jump to the start and end of a line, or [PgUp]/[PgDn] to move pages at a time. Press [Alt] + [/] to go to the bottom of the document, and [Alt] + [\] to jump back to the top. Use [Ctrl] + [W] to search your file, pressing [Alt] + [W] to look for additional matches.
8 Write to a USB drive
What if you need to create a bootable USB drive from an ISO file you’ve downloaded? The dd tool leaps to the rescue, but we’d advise using it with care – the following command wipes the target drive as part of the copy operation, so be sure you’ve identified the correct drive before you begin using sudo fdisk -l : $ sudo dd if=filename.iso of=/dev/usb status=progress
As you’d expect, substitute /dev/usb with the correct drive identifier (such as /dev/sdc ).
The Terminal comes with lots of help and documentation for you to plunder as required.
Be careful creating folders with spaces in the title – we show you how to do it correctly