basic linux commands
Basic Linux commands used in day 2 day activities:
1. tty – reveals the current terminal
2. whoami – reveals the currently logged-in user
3. which – reveals where in the search path a program is located
4. type –
5. echo – prints to the screen
a. echo $PATH – dumps the current path to STDOUT
b. echo $PWD – dumps ths contents of the $PWD variable
c. echo $OLDPWD – dumps the most recently visited directory
6. set – prints and optionally sets shell variables
7. clear – clears the screen or terminal
8. reset – resets the screen buffer
9. history – reveals your command history
a. !690 – executes the 690th command in our history
b. command history is maintained on a per-user basis via:
i. ~/.bash_history
ii. ~ = users’s $HOME directory in the BASH shell
10. pwd – prints the working directory
11. cd – changes directory to desired directory
a. ‘cd ‘ with no options changes to the $HOME directory
b. ‘cd ~’ changes to the $HOME directory
c. ‘cd /’ changes to the root of the file system
d. ‘cd Desktop/’ changes us to the relative directory ‘Desktop’
e. ‘cd ..’ changes us one-level up in the directory tree
f. ‘cd ../..’ changes us two-levels up in the directory tree
12. Arrow keys (up and down) navigates through your command history
13. BASH supports tab completion:
a. type unique characters in the command and press ‘Tab’ key
14. You can copy and paste in GNOME terminal windows using:
a. left button to block
b. right button to paste OR Ctrl-Shift-v to paste
15. ls – lists files and directories
a. ls / – lists the contents of the ‘/’ mount point
b. ls -l – lists the contents of a directory in long format: Includes permissions, links, ownership, size, date, name
c. ls -ld /etc – lists properties of the directory ‘/etc’, NOT the contents of ‘/etc’
d. ls -ltr – sorts chronologically from older to newer (bottom)
e. ls –help – returns possible usage information
f. ls -a – reveals hidden files. e.g. ‘.bash_history’
Note: files/directories prefixed with ‘.’ are hidden. e.g. ‘.bash_history’
16. cat – concatenates files
a. cat 123.txt – dumps the contents of ‘123.txt’ to STDOUT
b. cat 123.txt 456.txt dumps both files to STDOUT
c. cat 123.txt 456.txt > 123456.txt – creates new concatenated file
17. mkdir – creates a new directory
a. mkdir testRH5 – creates a ‘testRH5’ directory
18. cp – copies files
a. cp 123.txt testRH5/
By default, ‘cp’ does NOT preserve the original modification time
b. cp -v 456.txt testRH5/
19. mv – moves files
a. mv 123456.txt testRH5/ – moves the file, preserving timestamp
20. rm – removes files/directories
a. rm 123.txt
b. rm -rf 456.txt – removes recursively and enforces
21. file – outputs the filetype in detail
22. touch – creates blank file/updates timestamp
a. touch test.txt – will create a zero-byte file, if it doesn’t exist
b. touch 123456.txt – will update the timestamp
c. touch -t 200801091530 123456.txt – changes timestamp
23. stat – reveals statistics of files
a. stat 123456.txt – reveals full attributes of the file
24. find – finds files using search patterns
a. find / -name ‘fstab’
Note: ‘find’ can search for fields returned by the ‘stat’ command
25. alias – returns/sets aliases for commands
a. alias – dumps current aliases
b. alias copy=’cp -v’