Print

Why GNU/Linux?

 

Linux Basics - Command Line Basics

Basics

Command-Line Syntax for this Manual

Orientation

Viewing and changing the present working directory:

pwd               # "Print working directory"; show your current path

ls                # "List" contents of current directory
ls -l             # Similar to ls, but provides additional info on files and directories
ls -a             # List all files, including hidden files (.name) as well
ls -R             # Lists subdirectories recursively
ls -t             # Lists files in chronological order

cd <dir_name>     # "Change directory" to specified path
cd                # Brings you back to your home directory
cd ..             # Moves one directory up
cd ../../         # Moves two directories up (and so on)
cd -              # Go back to you were previously (before the last directory change)

The tilde symbol (~) gets interpreted as the path to your home directory when by itself or at the beginning of a word:

echo ~            # View the full (complete) path of your home
find ~            # List all your files (including everything in sub-directories)
ls ~              # List the top level files of your home directory
du -sch ~/*       # Calculate the "disk usage" of files in your home

Viewing file info, user, and host:

stat <file-name>  # Show last modification time stamps, permissions, and size of a file

whoami            # Shows your user name (same as "echo $USER")
hostname          # Shows on which machine you are (same as "echo $HOSTNAME")

Files and directories

mkdir <dir_name>   # Creates specified directory
rmdir <dir_name>   # Removes empty directory
rm <file_name>     # Removes file_name
rm -r <dir_name>   # Removes directory including its contents, but asks for confirmation
rm -rf <dir_name>  # Same as above, but turns confirmation off. Use with caution
cp <name> <path>   # Copy file/directory as specified in path (-r to include content in directories)
mv <name1> <name2> # Renames directories or files
mv <name> <path>   # Moves file/directory as specified in path

Copy and paste

The methods differ depending where you are.

Handy shortcuts

Ctrl+a    # Cursor to beginning of command line
Ctrl+e    # Cursor to end of command line
Ctrl+w    # Cut last word
Ctrl+k    # Cut to the end of the line
Ctrl+y    # Paste ("yank") content that was cut earlier (by Ctrl-w or Ctrl-k)

Other Useful Unix Commands

df          # disk space
free -g     # memory info in Megabytes
uname -a    # shows tech info about machine
bc          # command-line calculator (to exit type 'quit')
wget ftp://ftp.ncbi.nih.... # file download from web
/sbin/ifconfig # give IP and other network info
ln -s <original_filename> <new_filename> # creates symbolic link to file or directory
du -sh      # displays disk space usage of current directory
du -sh *    # displays disk space usage of individual files/directories
du -s * | sort -nr # shows disk space used by different directories/files sorted by size

Unix Help

help <command>  # Show help for a Bash command
man <something> # Show the manual page for a program (press the 'q' key to exit) 
man wc          # Manual on program 'word count' wc
wc --help       # Short help on wc
soap -h         # For less standard programs 
Category: Linux