免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 834 | 回复: 0
打印 上一主题 下一主题

Basic Linux Commands [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-01-24 18:46 |只看该作者 |倒序浏览
###Basic
Linux
Commands###
1. tty - reveals the current terminal
2. whoami - reveals the current login
3. which - reveals where in the search path a program is located
4. echo - prints to the screen
a. `echo $VAR` - dumps the current varible to STDOUT
b. `echo $PWD` - dumps the contents of the $PWD variable
c. `echo $OLDPWD` - dumps the most recently visited directory
d. `echo $?` - shows the state of the previous command
    0 succeed
    1 failure
    127 not a correct command
    126 can't execute
   
5. set - prints and optionally sets
shell
varibles
6. clear - clears the screen
7. reset - resets the screen buffer
8. 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:
~/.bash_history
~ = user's home directory
9. pwd - prints the working directory
10. cd - chages directory to desired directory
a. `cd`,`cd ~` with no options changes to the $HOME directory
b. `cd /` changes to the root of the file system
c. `cd Desktop/` changes us to the relative directory 'Desktop'
d. `cd ..` chages us one-level up in the directory tree
f. `cd ../..` changes us two-level up in the directory tree
11. Arrow keys (up and down) navigates through your command history
12. BASH  supports tab completion: type unique
a. type unique characters in the command and press 'Tab'
13. 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
14. 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: permitions, links, ownership, size, date, nameinfo
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'
g. `ls -i` - reveals i-notes of files
h. `ls -lh` - reveals in a human-read mode
Note: files/directories prefixed with '.' are hidden. e.g. '.bash_history'
inote represents the actuall storage unit of a file
15. cat - catenate files (tac in reverse)
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 catenated file
d. `cat -s data1 - shorten blanks to one when catenating
e. `cat -E` - display $ at end of each line
16. mkdir - creates a new directory
a. `mkdir testRH5` = creates a 'testRH5' directory
17. cp - copies files
a. `cp 123.txt testRH5/` copy 123.txt to testRH5/
By default, 'cp' does NOT preserve the original modification time
b. `cp -v 456.txt testRH5/` gives out a view while coping
18. mv - moves files
a. `mv [-v] 123456.txt testRH5/` - moves the file, preserving timestamp
19. rm removes files/directories
a. `rm 123.txt`
b. `rm -rf 456.txt` - removes recursively, and enforces
20. touch - creates blank files/updates timestamp
a. `touch test.txt` - create a zero-bytes file in case it does not exist
b. `touch file{1,2,3,4,5}` - create file1 file2 file3 file4 file5
c. `touch 123456.txt` (123456.txt already exists) - will update the timestamp
d. `touch -t 200901221530 123456.txt` changes timestamp
21. stat - reveals statistics of files
a. `stat 123456.txt` - reveals full attributes of the file
22. find - finds files using search patterns
a. `find / -name fstab`
Note: 'find can search for fields returned by the 'stat' command
23. alias - returns/sets aliases for
commands
a. `alias` - dumps current aliases
b. `alias copy='cp -v'`
24. more|less - paginators, which display text one-page at a time
1. more /etc/fstab
25. seq - echoes a sequence of numbers
a. `seq 1000` > 1thousand.txt - creates a file with numbers 1-1000
26. su - swiches users
a. `su` - attemps to log in as 'root'
27. head - displays opening lines of text files
a. `head /var/log/messages` - displays the opening lines of files
28. tail - displays the closing liness of text files
a. `tail /var/log/messages`
29. wc - counts words and optionally lines and words and letters of text files
a. `wc -l /var/log/messages`
b. `wc 123.txt`
c. wc -l data1 | cut -d ' ' -f 7 - cut the word on the 7th position ,with delimiter ' '
30. file - determines file type
a. 'file /var/log/message'
31. test - check file types and compare values
a. `test 2 -eq 3 ; echo $?` - test whether 2 equals 3
b. `[ a1 -nt a2 ]; echo $?` - test whether file a1 is newer than a2
c. `[ -e la ]; echo $?` - test whether file or directory la exists
d. `[ -f la ]; echo $?` - test whether la is a regular file
f. `[ -S la ]; echo $?` - test whether la is a socket file
g. `[ -s la ]; echo $?` - test whether ls is a log file
h. `[ -b /dev/sda ]; echo $?` - test whether /dev/sda is a block device
i. `[ -c a ]; echo $?` - test whether a is a character device
32. sleep - delay for some time
a. `sleep 5` - sleep for 5s
b. `usleep 5000` - sleep for 5ms
33. time - test the action time of a process
a. `time ls -ltr`
34. ps - report a snaport of the current processes
a. `ps` - current main processes
b. `ps -awx` - all the current processes
35. watch - execute a program periodically, showing output fullscreen
36. date - print or set the system time and date
a. `date` current date
b. `date -r grub.conf` print the action time of grub.conf
c. `date -r grub.conf +%s` print the number of seconds
36. expr - evaluate expression
a. `expr 10 + 10 (10 \* 10 )`
b. `expr as = As`
c. `expr substr as = 1 3`
Note: expr boolean 1 true 2 false
37. bg & fg - push the job into the background / frontground
a. `fg 7790`
Note: Ctrl + z push the current job into the background
38. sort - sort lines of files
a. echo 1 2 3 a b aa | sort > op1.txt
b. seq 100000 | sort > op2.txt
39. uniq - delete the repeated words
a. sort t1.txt | uniq
40. cut - remove sections from each line of files
a. cat /etc/passed | cut -d: -f
41. tr - translate or delet characters
a. `echo file1 | tr A-Z a-z`
b. `echo [:upper:] [:lower:]`
42. read - give a variable a value
a. `read test`
b. `read -n 3 $answer
43. unset - unset a variable
a. `unset firstname`
44. source - execute and give the out-put
45. export - change a variable to environment variable
| - pipe the out-put of a command to another
> - give out the out-put to a file
>> - add the out-put to the end of a file
; - execute the command after the former one
( ) - execute the commands in the bracket first
|| - execute if the former $? != 0
&& - execute if the former $? = 0
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/91804/showart_1807860.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP