Getting To Know Your System: Basic Terminal Operations Guide
Knowing how to get around the Terminal is crucial to getting any further in its understanding in the first place. On any given command, appending “–help” or typing “man” and the command name will list very helpful informatino and additional options. Keep in mind, when specifying multipled options, you may add them together, i.e. “ls -lah” instead of “ls -l -a -h” Let’s go over the basic operations:
- pwd – this will output your present working directory
- cd – this will change directory, e.g. cd /home/mikeyd
- mkdir – make a new directory
- rmdir – remove a directory. Syntax is the same as above “rm” See above for similar useful options.
- rm -r deletes a nonempty directory and all of its contents
- This will output the contents of the current directory.
- Specify a specific directory alternatively, e.g. “ls /home/mikeyd”
- Useful option are
- -a for all files
- -l for a “long format” listing of permissions.
- -h will show a column for the file sizes in human-readable format.
- -F will add a / to directories, @ to symbolic links, * to executables, | to pipes, or a = to sockets.
- My favorite is “laugh”, i.e. “ls -lahF” 🙂 Plus it is easy to remember!
- Type a partial command if you are unsure of the full tab and tap TAB. Magic!
- Copy a file.
- Basic syntax is “cp /path/to/original/file /path/to/new/file”
- Useful options are:
- -p to copy file permissions
- -a to copy a diretory hierarchy recursivly, preserving all file atributes and links (most common and sugggested)
- -r to copy a directory hierarchy recursivly only
- -i is the interactive mode which will ask for permission before replacing files and such
- -f will force the copy, overwriting destination files without prompt.
- Rename (“move”) a file.
- Basic syntax is “mv filename newfilename”.
- Also specifying a starting path and ending path will “cut” the file and “paste” it to another directory, similar to Windows.
- useful options:
- -i will use interactive mode, prompting for confirmation on replacing files
- -f will force the move, suppressing any prompts
- Remove a file.
- Basic syntax is “rm file”
- You may need to run this command as a superuser if ran against a file not owned by you, or because of lack of permissions applied to you on the file.
- Useful options:
- -i interactive mode
- -r remove a directory and all its contents (be very* careful of using this)
- -f force the removal
(NEVER, ever, ever, ever run “rm -rf /” EVER. Thankfully the Linux kernel is smart enough to detect this and will catch you, asking to append a string to override the fail-safe.
- Makes links to a file.
- These can either be a “hardlink” or “softlink” (also known as a symbolic or symlink).
- The link will be broken if the original file is removed.
- A hardlink makes a “second name” for a file, and is often not used as much for a typical user.
- You can think of a hardlink as each “link” pointing directory to the location of the file on the haddisk, while a softlink points to the original file only.
- A hardlink cannot “cross over” into other disks, while a softlink can. A softlink can also point to a directory, and a hardlink cannot (unless you specify the -d option as a superuser).
- Useful options:
- -s is similar to creating a “shortcut” in windows. The most common command would be “ln -s /path/to/target /location/of/link” where the -s option specifies a “soft link.”
- -i interactive mode
- -f will force the link, supressing confirmations
- -d will create a hard link to a directory (requires root access)
Prefix a text file with the command or alternatively “pipe” the information to the command (i.e. “dmesg | tail”). Piping will output to a new screen rather than the current screen (e.g. cat myfile), but does not work wither every file, rather it is intended for command output. Be advised when piping output, you must start with a command, such as “cat myfile | less” Press “h” while in “less” to see all help information or type “less –help” on the command line.
cat – meow…cough. This command will output a file to the screen in its entirety
less – view text files one page at a time.
head – View the first lines of a text file
tail – view the last lines of a text file, e.g. “dmesg | tail”
nl – view a text file with line numbers
strings – display text that’s embedded in a binary file
od – view data in octal formats, as well as other formats
xxd – view data in hexadecimal
acroread – view PDF files
gv – View PostScript of PDF files
Any questions/criticisms/suggestions, please leave them in the comments below: