Frequently used Linux commands are listed in the table below. Parameters listed in < > are REQUIRED, parameters listed in [ ] are OPTIONAL
Additional help is always available online by typing man <command> for each of the commands listed below. The behavior of most commands may be modified by adding options as illustrated under the ls command. This is only a quick command summary guide. Refer to the man pages for more detailed information. You may also browse Linux related documentation on Galileo's Documentation Page.
List files. If no directory is given, files in the current directory are listed.
ls # Lists files in current directories ls lab1* # Lists files in the current directory beginning with the string lab1 ls -l # Gives a long listing showing file attributes and file access permissions ls -t # Lists files starting with newest files first ls subdir # Lists files in directory subdir # (where subdir is under the current directory)
Print working directory: displays the name of the current directory.
Change directory: change your default directory
cd # change directory to your home directory cd .. # move up one directory cd lab1 # move down into directory lab1 from your current directory cd lab1/problem1 # move down into directory lab1/problem1 from your current directory
Remove command: used to delete files.
rm junk.dat # deletes the file named junk.dat rm * # deletes all files from your current directory (Be careful w/ this command!)
Copy command. Copies file sourcefile to target targetfile
cp file1 file2 # copy file1 to the a new file called file2. cp file1 subdir/file1 # copy the file file1 into the subdirectory subdir. cp file1 subdir # copy the file file1 into the subdirectory subdir, # if subdir exists, else copy file1 to a file called subdir!
Move or rename command. Renames sourcefile to targetfile.
mv my_file my_old_file # rename the file my_file to my_old_file \\ mv file.dat subdir/file.dat # move the file file.dat into the subdirectory subdir. \\ mv file.dat subdir # move the file file.dat into the subdirectory subdir, # if subdir exists, else rename file.dat to subdir!
Make directory. Creates a new directory.
mkdir test # makes a directory called test under the current directory \\ mkdir test/first # makes a directory called test/first under the current directory # (the test directory must already exist for this command to work) mkdir -p test/first # makes a directory called test/first under the current directory , # if test does not exist, create this directory as well
Remove directory. Remove a directory. The directory must be empty before it can be removed.
rmdir test # removes directory named test from the current directory
Change the mode for a file. Each file on a LINUX system has permissions such as read, write, and execute. Doing an ls -l will list files along with their permission settings. Permissions may be set for three different kinds of users: the file owner/user (u), group members (g), or other users (o).
chmod og-r file.txt # disallow reading of file.txt by others/group members. chmod og+r file.txt # allow reading of file.txt by others/group members. chmod o+x file.exe # allow execution of file.exe by other users. # chmod may be used on directories as well to allow or to prevent access to the files stored there. chmod o-x file.exe # disallow other users from entering this directory.
Prints the contents of a file to the screen.
more/less are used to display a text file on your screen on page at a time. To 1st order they are interchangeable, but less displays the results of your searches more clearly.
While viewing the file press:
return to advance the display by one line
space to advance the file by one screen full
b to go back by one screen full
/ to search. After pressing /, enter the text you wish to search for and hit return. Hitting / and return again will find the next occurrence of your text. less is better here, because it will highlight the found text. q to quit
Grep will print out all occurrences of the string text in the file filename.
Print the first 10 (default) lines of the file filename.
head file.txt # prints the 1st 10 lines of file.txt to the screen head -n 20 file.txt # prints the 1st 20 lines of file.txt to the screen
Print the last 10 (default) lines of the file filename.
tail file.txt # prints the last 10 lines of file.txt to the screen tail -n 20 file.txt # prints the last 20 lines of file.txt to the screen
Open a secure shell connection to a remote host.
ssh -l myusername galileo.phys.virginia.edu Opens a secure connection to Galileo.
Change your password. You will be prompted for your old and new passwords.
To force a program to stop running, press Control-C (^C) in the terminal where the program was started.
Log out from your LINUX account.