Thursday, December 31, 2009

BASIC LINUX COMMANDS

BASIC LINUX COMMANDS

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. echo - prints to the screen
1.echo $PATH - dumps the current path to STDOUT
2.echo $PWD - dumps ths contents of the $PWD variable
3.echo $OLDPWD - dumps the most recently visited directory
5. set - prints and optionally sets shell variables
6. clear - clears the screen or terminal
7. reset - resets the screen buffer
8. history - reveals your command history
!690 - executes the 690th command in our history
command history is maintained on a per-user basis via:
~/.bash_history
~ = users's $HOME directory in the BASH shell
9. pwd - prints the working directory
10. cd - changes directory to desired directory
'cd ' with no options changes to the $HOME directory
'cd ~' changes to the $HOME directory
'cd /' changes to the root of the file system
'cd Desktop/' changes us to the relative directory 'Desktop'
'cd ..' changes us one-level up in the directory tree
'cd ../..' changes us two-levels up in the directory tree
11. Arrow keys (up and down) navigates through your command history
12. BASH supports tab completion:
type unique characters in the command and press 'Tab' key


13. You can copy and paste in GNOME terminal windows using:
left button to block
right button to paste OR Ctrl-Shift-v to paste
14. ls - lists files and directories
ls / - lists the contents of the '/' mount point
ls -l - lists the contents of a directory in long format:
Includes: permissions, links, ownership, size, date, name
ls -ld /etc - lists properties of the directory '/etc', NOT the contents
of '/etc'
ls -ltr - sorts chronologically from older to newer (bottom)
ls --help - returns possible usage information
ls -a - reveals hidden files. e.g. '.bash_history'
Note: files/directories prefixed with '.' are hidden. e.g. '.bash_history'
15. cat - catenates files
cat 123.txt - dumps the contents of '123.txt' to STDOUT
cat 123.txt 456.txt dumps both files to STDOUT
cat 123.txt 456.txt > 123456.txt - creates new catenated file
16. mkdir - creates a new directory
mkdir testRH5 - creates a 'testRH5' directory
17. cp - copies files
cp 123.txt testRH5/
By default, 'cp' does NOT preserve the original modification time
cp -v 456.txt testRH5/
18. mv - moves files
mv 123456.txt testRH5/ - moves the file, preserving timestamp
19. rm - removes files/directories
rm 123.txt
rm -rf 456.txt - removes recursively and enforces
20. touch - creates blank file/updates timestamp
touch test.txt - will create a zero-byte file, if it doesn't exist
touch 123456.txt - will update the timestamp
touch -t 200801091530 123456.txt - changes timestamp

21. stat - reveals statistics of files
stat 123456.txt - reveals full attributes of the file
22. find - finds files using search patterns
find / -name 'fstab'
Note: 'find' can search for fields returned by the 'stat' command
23. alias - returns/sets aliases for commands
alias - dumps current aliases
alias copy='cp -v'

No comments:

Post a Comment