Maximum PC

Start making good use of the Terminal with this collection of commands

-

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 also useful, providing you with a brief descriptio­n of a fully formed command:

$ whatis apt-get install vlc

This describes the “apt-get” tool, the install argument, and the package “vlc.” Note: “whatis” ignores any flags.

The Terminal also provides access to an online manual via the “man” utility. Start with “man intro” for a detailed intro to the Terminal, and “man man” for advice on navigating the manual. Pair it with a tool—for example, “man apt-get”—for a detailed descriptio­n of that tool. Navigating the Filesystem Open the Terminal, and you start in your home folder. Use “ls -l” to confirm this. If you’d like to view all hidden files and folders (file names with a period at the beginning, such as “.hidden.sh”), use “ls -a.” View the contents of subfolders in the current folder with “ls --recursive.”

The “cd” command allows you to quickly move between directorie­s. To move inside a subfolder within the current folder, use “cd Dirname” (folders and files are casesensit­ive). 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 to another folder using its exact path (“cd ~/Document” if it’s in your home folder). Type “cd -” to go back to the previous directory.

If your folder path contains spaces—for example, a folder named “Star Trek,” you need to encompass the entire path inside single quotation marks, like so:

$ cd ‘~\Videos\Star Trek’

Copy, Move, and Delete Need to manipulate files within the Terminal? Start by familiariz­ing yourself with the “cp” (copy) and “mv” (move) tools, which share the same syntax:

$ cp -i source destinatio­n

Both “source” and “destinatio­n” can be complete folder paths, or just use the file name 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 destinatio­n: “~/Documents/Backup/ invoice-backup.odt,” for example. Similarly, “cp invoice. odt invoice-backup.odt” creates a renamed duplicate of the original file in the same folder. Substitute “mv” if you wish to move—or rename—a file. If you want to copy

a folder, use the “-r” flag to indicate recursion, which means the folder and its contents are 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

Create folders using “mkdir foldername” (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, surround them with single quotation marks or place a backslash (\) before the space—for example, “mkdir Star\ Trek.” Change Permission­s Nautilus provides some tools for tweaking permission­s, but it’s quicker to use “chmod” with 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 subdirecto­ries—to the same permission­s as the folder itself, add the “-R” flag, like so:

$ chmod -R 777 folder

The key element is the “777,” which refers to the permission­s: “7” stands for “rwx” (full access), and the first number refers to the file owner, the second to the file’s group, and the third to “everyone else.”

Other numbers worth considerin­g are “6” (rw-, or read/write but not 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 restrictin­g 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 permission­s, read https://help. ubuntu.com/community/FilePermis­sions for a full brief. 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 use “chown” to change both user and group with one command, like so:

$ chown owner:group file

Run Multiple Commands Together There are three ways to join two or more commands together on a single line (allowing you to go off while your PC gets on with it). If you only want the second command to run if the first completes successful­ly, use “&&”:

$ 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 semi-colon (;) to run the second command regardless of what happens with the first:

$ sudo apt-get update ; sudo apt-get remove vlc

Editing with Nano One popular use for the Terminal is to edit configurat­ion 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 see the Terminal change to the Nano interface— the file name and path are 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 and End to jump to the start and end of a line, or PgUp and 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. Write to USB Need to create a bootable USB drive from an ISO file you’ve downloaded? The “dd” tool leaps to the rescue, but use 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

Substitute “/dev/usb” with the correct drive identifier (such as “/dev/sdc”).

 ??  ?? The Terminal comes with lots of help and documentat­ion for you to plunder as required.
The Terminal comes with lots of help and documentat­ion for you to plunder as required.
 ??  ?? Use “nano” to edit config files without leaving the Terminal.
Use “nano” to edit config files without leaving the Terminal.
 ??  ?? Create bootable flash drives from ISO files using the “dd” tool.
Create bootable flash drives from ISO files using the “dd” tool.

Newspapers in English

Newspapers from United States