Linux General Commands
This is a more generalized listing of different commands used in navigating and manipulating linux environments and programs.
General Commands
These commands are good to keep in mind when working in a command line shell on a Unix-like computer.
- man command : Gives information from the UNIX manual about command. Text is displayed using less(below).
Also, man -k word will list manual pages whose titles contain the keyword word. Use this command for more information on the following commands. - Ctrl+C : Usually kills whatever you are doing and signals the shell to accept the next command. Use Ctrl+C only if you are stuck, since work you did during the killed command may be lost.
- Ctrl+Z : This control code temporarily suspends a running command, whereupon the shell can accept the next command. Use the fg (foreground) command to get the suspended process running again; type jobs to see if you have any suspended or background processes. Or use the bg command to have the last suspended job run in the background.
- cd dir : Changes the current working directory to dir.
- cp file1 file2: Copy a file
- date :Displays the current date and time.
- gzip file : Compresses file. The full-size file is removed and the compressed file has the same name with an extension of ".gz" added. You can get 4 to 1 compression on low-entropy data.
- grep pattern file : Search the file for the specified pattern.
- gunzip file :The inverse of gzip: restores the original file.
- kill pid : Cancel the process with identification pid
- ls : List the files in the current directory. Also, ls path lists the files in the directory path.
- pkill process : Cancel the named process - e.g. pkill mybustedscript
- less : Displays text files one page at a time. Press "h" for help, "q" to quit", SPACE to go to the next page, "b" for previous page, "/" to search, etc.
- mkdir dir : Creates a new directory dir.
- logout : Ends your session. If you ran multiple shells you may need to run this for each nested process. CTRL-D from a shell prompt does the same.
- mv oldname newname : Move and/or rename a file.
- nice -prior program : Gives program processing priority value prior (1 being the highest priority level and 19 the lowest) which tells the computer how to process tasks.
e.g. nice -19 ./a.out & runs the program a.out in the background at the lowest priority. - rm file : Deletes file.
- rmdir dir : Deletes the empty directory dir.
- command1 | command2 : Called the “pipe” command. Takes the output of command command1 and uses it as the input for command2.
e.g. ls | less lists files in the current directory and views the results in a paginated form - touch file : Create an empty file named file.
- uptime : Shows the time since the last boot plus the load on the computer
- who : Lists all users on the computer in which you are currently working.