Linux Useful Commands

From CsWiki
Revision as of 13:40, 11 April 2018 by Naamaplay (Talk | contribs)

Jump to: navigation, search

A

alias

A way to run a command or a series of Unix commands using a shorter name than those that are usually associated with such commands.

apt-get

Apt-get is a tool to automatically update a Debian machine and to get and install Debian packages/programs.


Aspell

GNU Aspell is a free and open source spell checker designed to replace Ispell. It can either be used as a library or as an independent spell checker.

AWK, Gawk

A programming language tool used to manipulate text. The language of the AWK utility resembles the shell programming language in many areas, although AWK's syntax is very much its own.

B

bzip2

A portable, fast, open source program used to compress and decompress files at a high rate.

C

cat

A Unix/Linux command that can read, modify or concatenate text files. Cat commands are most commonly used for displaying the contents of a file.

cd

The cd command changes the current directory in Linux and can toggle between directories conveniently. Cd is similar to the CD and CHDIR commands in MS-DOS.

chmod

Chmod changes the access mode (permissions) of one or more files. Only the owner of a file or a privileged user may change the access mode.

chown

Chown changes file or group ownership and has the option to change ownership of all objects within a directory tree, as well as having the ability to view information on objects processed.

cmp

The cmp utility compares two files of any type and writes the results to the standard output. By default, cmp is silent if the files are the same; if they differ, the byte and line number at which the first difference occurred is reported.

comm

Comm compares lines common to file1 and file2.The output is in three columns; from left to right: lines unique to file1, lines unique to file2 and lines common to both files.

cp

The cp command copies files and directories; copies can be made simultaneous to another directory if the copy is under a different name.

cpio

Cpio copies files into or out of a cpio or tar archive. A tar archive is a file that contains other files, plus information about them, such as their file name, owner, timestamps and access permissions. The archive can be another file on the disk, a magnetic tape or a pipe. Cpio has three operating modes and is a more efficient alternative to tar.

CRON

CRON is a Linux system process that will execute a program at a preset time. To use CRON, a user must prepare a text file that describes the program to be executed and the times at which CRON should execute them. Then the crontab program can be used to load the text file that describes the CRON jobs into CRON.

D

Home directories

User's home directories are located as follows:

File System TypePathShorthand
Primary/cs/usr/login~
Safe/cs/+/usr/login~/safe
Secondary/cs/+/usr/login~/.+
Tertiary/cs/++/usr/login~/.++

Note: ~ is a UNIX alias to one's home directory. ~/safe, ~/.+ and ~/.++ are symbolic links under ~. See ln(1).

N.B. Groups stud, studap, grad and cgrad have ~/safe directories.

Snapshot and Backups

Snapshots

Snapshots are short-term online backups. There are three types of snapshots: hourly, daily and weekly. Snapshots cycle out -- i.e. if N hourly snapshots are defined for a filesystem, when the next snapshot is created, the oldest ([N+1) snapshot disappears permanently. Note that online means that the snapshots are part of the filesystem. If a filesystem becomes unavailable due to a fileserver failure, the snapshots are unavailable as well.

Snapshots are available in the special .snapshot directory and can be accessed using the snapshot utility or directly (e.g. "cd .snapshot"). Note that the .snapshot doesn't show up when searching a directory (i.e. "ls -a" won't show it), but it exists and can be "cd"-ed into.

The current snapshot schedule is as follows:

File System TypePathHourlyDailyWeekly
Primary~24148
Safe~/safe24148
Secondary~/.+24148
Tertiary~/.++000
Graduate Labs/cs/labs/supervisor/login010

Note that tertiary directories (~/.++) have no backups whatsoever.

Various labs have specialised filesystems. The snapshot policy of each and every such filesystem is determined according to the lab's needs/requests.

Backups

Currently, undergraduate and graduate directories have snapshots only.

In the future, offsite mirroring of primary, safe and secondary directories is planned.

Also in the future, offsite backups for longer-term retention is planned in coordination with the Computation Authority.

Disk space shortage

Logging in without quota

If there is insufficient disk space, some window managers might not start at all (e.g. xfce4, or KDE). When this happens you'll receive some message of insufficient quota, or an error message saying the Xsession has terminated too quickly. In this case, to be able to login and clean up your quota, you'll have to login using xterm.

There are 2 ways to login in xterm:

  1. When the chooser appears, choose XTerm instead of the normal window manager you use.
  2. Before logging in (i.e. entering the username and password), click on the Session button, and choose Failsafe Terminal

After you've logged in, you'll get a simple xterm window. There you can start cleaning up your quota as described in the following sections. When finished, simply type exit, and re-login again.

Note: Without a window manager, to write commands to the xterm window, you'll have to place the mouse courser on that window.

Basic cleanup

Some basic utilities to manage disk space:

  1. Are you using safe or secondary storage area (~/safe and ~/.+)?
    If not there's more space there you can use. Note that with ~/.+ the backup is less often, so it is not advisable to use it on active projects.
  2. Use the cleanup script to remove files that can be safely deleted:
    cleanup
  3. Use du to find how space is distributed within your home directory:
    du ~ | sort -n
    Note that this will also show you the space taken by files beginning with '.' which do not normally show in directory listings.
    A more elaborate usage of the du utility is:
    \ls -A1 | sed "s#'#\\\'#" | sed 's/ /\\ /g' | xargs du -sckx -- | sort -n
    Which will calculate the sum of each directory (in the current directory). New students have an alias for this as dua.

Mail

This section only applies for those using a local program for reading mail (e.g. thunderbird, kmail, etc.), if you are using a web browser to read the mail (e.g. the mail.huji mail account's web interface) this does not apply.

  • By default, your mail is saved under your home directory. Old mail and mail with big attachments (multimedia, PDFs, junk) can cause space shortage. To avoid it, remember to periodically clean up your inbox.
  • You should be able to see if the mail is taking your disk space by using the above du command, either ~/Mail, or ~/.mozilla-thunderbird will take a lot of space (depending on your mail client).
  • On some mail clients (e.g. thunderbird/icedove, kmail) simply deleting the mail isn't enough. You need to compact the inbox folder (or other folders, if you use any). You can do this (in kmail and thunderbird/icedove), by right clicking on the folder, and choosing "Compact this folder".
  • On thunderbird/icedove, you can tell the program to do this automatically by setting:
    Edit -> Preferences -> Advanced -> Offline & Disk Space -> Compact folders when ...
    For new users, it is already set (so old users can use reinstall thunderbird, to set this configuration).
    • Sometimes, when very low on memory compacting doesn't work. In that case, you can either:
      1. Better: reinstall thunderbird - reinstall also compacts the folders (specifically, the Inbox, Sent, and Trash).
        or
      2. Risky: Run the script /cs/share/scripts/compact-thunderbird.sh.
Warning: Please note that you need to close thunderbird before running these scripts.
These methods should be executed only once, since after changing the preferences and compacting the folders, thunderbird should be able to manage the compcat by itself (and it will do so each time you open it).