Linux
  1. Ivec provides several training courses, including a Linux course
  2. 8 beginner tutorials to the Linux system with an example file to work through are also available at the University of Surrey
  3. The tab key auto-completes commands on the Linux terminal. This is extremely useful and saves time! The down-arrow key can be used to re-run previous commands. It is also very useful.
  4. Basic “Must-know” linux commands:
    ssh
    A program for logging into a remote machine and for executing commands on a remote machine. It is intended to replace rlogin and rsh, and provide secure encrypted communications between two untrusted hosts over an insecure network. X11 connections and arbitrary TCP ports can also be forwarded over the secure channel.
    cd
    Change Directory - change the current working directory to a specific Folder, i.e., cd some_dir. If you run the cd command alone, you will be send to your $HOME directory.
    ls
    List information about files. "ls -l" gives more useful information that ls alone. The use of wildcards is very useful. For example to list all files ending with ".nc", one would to "ls -l *.nc". "ls -lrt" will list files in the order that they were last modified, in this case, the last modified file will appear last. "ls -lah" will display hidden files. In Linux hidden files start with a "." (dot), for example the .bashrc file in your $HOME directory.
    tail
    Output the last part of files, print the last part (10 lines by default) of each FILE
    tail reads from standard input if no files are given or when given a FILE of ‘-’. To output say the last 20 files, one would use "tail -n 20 file_name".
    head
    Output the first part of files, prints the first part (10 lines by default) of each file, i.e., does the opposite of tail command.
    cat
    Concatenate and print (display) the content of files.
    less
    Display output one screen at a time, Search through output, Edit the command line.
    mv
    Move or rename files or directories.
    cp
    Copy one or more files to another location
    Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY. To copy a directory recursively, use "cp -r"
    ln
    Make links between files, by default, it makes hard links; with the -s option, it makes symbolic (or "soft") links.
    rm
    remove/delete a file. Use "rm -f file_name", if it's possible the file does not exist, but you want to be sure anyway. This is useful in scripting.
    pwd
    Print Working Directory (shell builtin).
    mkdir
    Create new folder(s), if they do not already exist. Use "mkdir -p some_dir" if the directory may already exist.
    rmdir
    Remove directory, this command will only work if the folders are empty. To delete a directory recursively use "rm -rf dir_name". You must be very careful when using "rm -rf" and be sure you are not deleting anything important.
    tar
    Create an archieve of many other files into one file. Very useful command. tar is also used to un-tar a tar file
    chmod
    Change access permissions, change mode. To change permissions recursively, use "chmod -R some_dir". chmod is used to give read (r), write(w), and execute(x) permissions. chmod also takes as input the user(u), the group(g), and all the rest of the world(a). One should almost never use the "a" option. To give read-write-execute access to the group, one would use "chmod -R g+rwx some_dir".
    export
    Set an environment variable. Mark each name to be passed to child processes in the environment.

    More commands can be found on linoxide.

  5. Help for any command can be found using “man”, e.g., “man cp”. Note that man pages can by somewhat cryptic, and a Google search usually gives the answer much faster than trawling though man pages, which can be very long.
  6. Each command can be executed with large number of options, and only a few have been listed above. There are too many to document, and Google search is the way to go! Alternatively, use explain shell. It only shows you the part of the commands that you type in. Click on the piping examples below to get an idea of how useful explain shell can be.
  7. The concept of piping
    • Piping (used with “|”, this is not alphabet l but the vertical bar) is extremely useful to run two or more linux commands sequentially, for example, get the list of first 10 files “ls –l | head –n 10”.
    • How many files in my directory:ls -l | wc -l
  8. Shells
    • There are many shells, the easiest and most popular is the Bourne Shell (bash). A shell language is used to to run a series of linux commands, and is very useful. A bash script must always start with:
      #!/bin/bash
      echo "hello world"
      

    • After writing a shell, you need to make it executable, chmod u+x script_name. To execute it, simiply “./script_name”.
    • For comments, use #
    • For printing, use “echo”.
    • The web is full of examples, have a look.
    • Bash Guide is a good place to start learning bash.
  9. More advanced commands:
    • sed – to find and replace strings in a file, and much more
    • grep – scan a file for particular strings, and much more
  10. The .bashrc file is a very important file which lives in your $HOME directory. It is run/called at every login and interactive shell command, e.g., ssh. It is where one may define their own particular environment variables. One should always be very careful when editing the .bashrc file.
    [[li]]Defining your own aliases. An alias is like a shortcut to a command(s). Aliases are useful to shorten long commands and should be defined in the .bash_profile file in $HOME. For example:
    alias cdjat="cd /scratch/y98/jatinkala/"
    alias cdshr="cd /scratch/y98/shared/"
    alias jj="qstat -u jatinkala"
    

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License