Basic Linux Intro

From Genome Analysis Wiki
Jump to: navigation, search

Unix/Linux Basic Commands

Use man to see the options for each command (especially grep)


Get more details on a given command man command
Change Directories
Move to a different Directory cd pathToGoTo
Move up a directory cd ..
Move up 2 directories cd ../..
See what directory you are in pwd
Look in Directories
See what files are in the current directory ls
See what files are in a different directory ls pathToDir
See hidden files (start with .) ls -a
See detailed file listing ls -l
Copy/Move/Link Files
Copy a file cp origFile newFileName
Copy a file to current directory with original name cp origFile .
Move a file mv origFile newFileName
Link to a file (rather than copy - uses less space/quicker it is not a new file, just a reference to the original. If you change the linked file, you change the original) ln -s origFile newFile
Remove Files/Dirs & Create Dirs
Remove/Delete a file rm fileName
Create a new directory mkdir dirName
Create a directory & subdirectories mkdir -p dirName/subDir/subDir2
Remove a directory rmdir dirName
Search
Search for a file in dir/subdirs (use * for wildcard matching) find . --name "fileName"
Search for text in files (can use * for all files) grep textToFind filesToSearch
Look at Files
Look at file less fileName -or- more fileName
Look at just beginning of the file head fileName
Look at end of file tail fileName
Compare files diff file1 file2
Permissions
Change directory/file permissions chmod newPermissions fileName
Processes
See what you have running ps -ef | grep yourUserName
Kill/end a job you don't want running kill -9 process#FromPs


Notes on directories:

  • . Refers to current directory
  • .. Refers to one directory up
  • ../.. refers to 2 directories up
  • ../../.. refers to 3 directories up
  • (etc)

The '*' star character is used to match any characters (0 or more). You can use it anytime you need to specify a filename(s) and it will use all the files in the current directory/path. It can also be used to wildcard match a partial file name: filePrefix* will match filePrefix1.txt and filePrefix2.txt

You can use alias to setup an alias for a command. See man to see how it is used.

Additional Resources

For more information, see:

CSG Documentation [AWK, BASH, UNIX commands and etc.]