Av en händelse hittade jag en sajt med en fullständig lista på alla vanligt förekommande nyttiga UNIX/LINUX-kommandon med bra förklaringar och exempel.
Listan är så pass bra att jag vill dela med mig av min "upptäckt". Sajten heter Unix systems Basic commands. Jag återger alla sajtens kommandon nedan.
- man ls will explain about the ls command and how you can use it.
- man -k pattern command will search for the pattern in given command.
# # ## # #####
# # # # # #
# # # # # #
# ## # ###### # #
## ## # # # #
# # # # # #
August 1965
S M Tu W Th F S
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
clear command clears the screen and puts cursor at beginning of first line.
12/20 Test new software.
1/15 Test newly developed 3270 product.
1/20 Install memory on HP 9000 machine.
Tty command
Tty command will display your terminal. Syntax is
tty options
- Options
- -l will print the synchronous line number.
- -s will return only the codes: 0 (a terminal), 1 (not a terminal), 2 (invalid options) (good for scripts)
back to top of misc commands
back to top of page
<!-- Misc commands end here --> <!-- File management commands start here -->
cat,cd, cp, file,head,tail, ln,ls,mkdir ,more,mv, pwd, rcp,rm, rmdir, wc.
/u0/ssb/sandeep
is output for the command when I use pwd in /u0/ssb/sandeep directory.
Ls command
ls command is most widely used command and it displays the contents of directory.
- options
- ls will list all the files in your home directory, this command has many options.
- ls -l will list all the file names, permissions, group, etc in long format.
- ls -a will list all the files including hidden files that start with . .
- ls -lt will list all files names based on the time of creation, newer files bring first.
- ls -Fxwill list files and directory names will be followed by slash.
- ls -Rwill lists all the files and files in the all the directories, recursively.
- ls -R | more will list all the files and files in all the directories, one page at a time.
Mkdir command.
mkdir sandeep will create new directory, i.e. here sandeep directory is created.
Wc command
wc command counts the characters, words or lines in a file depending upon the option.
- Options
- wc -l filename will print total number of lines in a file.
- wc -w filename will print total number of words in a file.
- wc -c filename will print total number of characters in a file.
resume1.doc: data
cal.txt: ascii text
- Some examples:
- mv oldfile newfile will rename oldfile to newfile.
- mv -i oldfile newfile for confirmation prompt.
- mv -f oldfile newfile will force the rename even if target file exists.
- mv * /usr/bajwa/ will move all the files in current directory to /usr/bajwa directory.
- Some examples:
- ln -s fileone filetwo will create a symbolic link and can exist across machines.
- ln -n option will not overwrite existing files.
- ln -f will force the link to occur.
Rm command.
To delete files use rm command.
- Options:
- rm oldfile will delete file named oldfile.
- rm -f option will remove write-protected files without prompting.
- rm -r option will delete the entire directory as well as all the subdirectories, very dangerous command.
Rmdir command.
rmdir command will remove directory or directories if a directory is empty.
- Options:
- rm -r directory_name will remove all files even if directory is not empty.
- rmdir sandeep is how you use it to remove sandeep directory.
- rmdir -p will remove directories and any parent directories that are empty.
- rmdir -s will suppress standard error messages caused by -p.
back to top of File management commands
back to top of page
<!--File management commands end here -->
<!-- Comparison and searching starts here -->
This is first file
this is second line
this is third line
this is different as;lkdjf
this is not different
This is first file
this is second line
this is third line
this is different xxxxxxxas;lkdjf
this is not different
diff fileone filetwo will give following output
4c4
< this is different as;lkdjf
---
> this is different xxxxxxxas;lkdjf
fileone filetwo differ: char 80, line 4
no changes
Dec 9 16:06 1997 dirone only and dirtwo only Page 1
./cal.txt ./fourth.txt
./dohazaar.txt ./rmt.txt
./four.txt ./te.txt
./junk.txt ./third.txt
./test.txt
ops 12964 25853 0 16:12:24 ttyAE/AAES 0:00 sleep 60
dxi 12974 15640 0 16:12:25 ttyAH/AAHP 0:00 sleep 60
ops 12941 25688 0 16:12:21 ttyAE/AAEt 0:00 sleep 60
ops 12847 25812 0 16:11:59 ttyAH/AAH6 0:00 sleep 60
ops 12894 25834 0 16:12:12 ttyAE/AAEX 0:00 sleep 60
dxi 13067 27253 2 16:12:48 ttyAE/ABEY 0:00 sleep 1
ops 13046 25761 0 16:12:44 ttyAE/AAE0 0:00 sleep 60
dxi 12956 13078 0 16:12:23 ttyAG/AAG+ 0:00 sleep 60
ops 12965 25737 0 16:12:24 ttyAE/AAEp 0:00 sleep 60
ops 12989 25778 0 16:12:28 ttyAH/AAHv 0:00 sleep 60
ssb 13069 26758 2 16:12:49 ttyAH/AAHs 0:00 grep sleep
pjk 27049 3353 0 15:20:23 ? 0:00 sleep 3600
- Options:
- -b option will precede each line with its block number.
- -c option will only print the count of matched lines.
- -i ignores uppercase and lowercase distinctions.
- -l lists filenames but not matched lines.
Some Examples:
find $HOME -print will lists all files in your home directory.
find /work -name chapter1 -print will list all files named chapter1 in /work directory.
find / -type d -name 'man*' -print will list all manpage directories.
find / -size 0 -ok rm {} \; will remove all empty files on system.
- -atime +n |-n| n will find files that were last accessed more than n or less than -n days or n days.
- -ctime +n or -n will find that were changed +n -n or n days ago.
- -depth descend the directory structure, working on actual files first and then directories. You can use it with cpio command.
- -exec commad {} \; run the Unix command on each file matched by find. Very useful condition.
- -print print or list to standard output (screen).
- -name pattern find the pattern.
- -perm nnnfind files whole permission flags match octal number nnn.
- -size n find files that contain n blocks.
- -type c Find file whole type is c. C could be b or block, c Character special file, d directory, p fifo or named pipe, l symbolic link, or f plain file.
back to top of misc commands
back to top of page
<!-- Comparison and searching ends here --> <!-- Text processing starts here -->
cut,paste, sort, uniq,awk,sed,vi.
this is firstline
this is secondline
this is thirdline
Examples:
cut -c1,4 testfile will print this to standard output (screen)
ts
ts
ts
It is printing columns 1 and 4 of this file which contains t and s (part of this).
- Options:
- -c list cut the column positions identified in list.
- -f list will cut the fields identified in list.
- -s could be used with -f to suppress lines without delimiters.
this is firstline
and a file named testfile2 contains
this is testfile2
then running this command
paste testfile testfile2 > outputfile
will put this into outputfile
this is firstline this is testfile2
it contains contents of both files in columns.
who | paste - - will list users in two columns.
- Options:
- -d'char' separate columns with char instead of a tab.
- -s merge subsequent lines from one file.
zzz
aaa
1234
yuer
wer
qww
wwe
Then running
sort testfile
will give us output of
1234
aaa
qww
wer
wwe
yuer
zzz
- Options:
- -b ignores leading spaces and tabs.
- -c checks whether files are already sorted.
- -d ignores punctuation.
- -i ignores non-printing characters.
- -n sorts in arithmetic order.
- -ofile put output in a file.
- +m[-m] skips n fields before sorting, and sort upto field position m.
- -r reverse the order of sort.
- -u identical lines in input file apear only one time in output.
sort names | uniq -d will show which lines appear more than once in names file.
- Options:
- -c print each line once, counting instances of each.
- -d print duplicate lines once, but no unique lines.
- -u print only unique lines.
- options:
- -e 'instruction' Apply the editing instruction to the files.
- -f script Apply the set of instructions from the editing script.
- -n suppress default output.
for more information about sed, enter man sed at command line in your system.
- options:
- i for insert mode.
- : for command mode.
- <escape> to invoke command mode from insert mode.
- :!sh to run unix commands.
- x to delete a single character.
- dd to delete an entire line
- ndd to delete n number of lines.
- d$ to delete from cursor to end of line.
- yy to copy a line to buffer.
- P to paste text from buffer.
- nyy copy n number of lines to buffer.
- :%s/stringA/stringb /g to replace stringA with stringB in whole file.
- G to go to last line in file.
- 1G to go to the first line in file.
- w to move forward to next word.
- b to move backwards to next word.
- $ to move to the end of line.
- J join a line with the one below it.
- /string to search string in file.
- n to search for next occurence of string.
back to top of Text processing commands
back to top of page
<!-- Text processing ends here --> <!-- shell programming starts here -->
Shell programming
,
,
,
,
,
,
,
,
.
- example:
- find / -name *.Z -print > compressedfiles
then after entering this command hitting - <control z>
key will suspend this job, then entering - bg
at command line will put this job in background, entering - fg
will put this job in foreground. Entering - jobs
at command line will show me all my concurrent jobs that are running.- Other common features
- > will redirect output from standard out (screen) to file or printer or whatever you like.
- >> filename will append at the end of a file called filename.
- < will redirect input to a process or commnand.
- | pipe output, or redirect output, good for joining commands, i.e. find command with cpio, etc.
- & at the end of command will run command in background.
- ; will separate commands on same line.
- * will match any characters in a file or directories. junk* will match all files with first 4 letters
- ? will match single characters in a file.
- [] will match any characters enclosed.
- () execute in subshell.
- ` ` to run a command inside another command and use its output.
- " " partial quote for variables.
- ' ' full quote for variables.
- # begin comment (if #/bin/ksh or csh or sh is entered at first line of script it runs script in that shell)
- bg background execution.
- break break from loop statements.
- continue Resume a program loop.
- Kill pid number will terminate running jobs
- stop will stop background job.
- suspend will suspend foreground job.
- wait will wait for a background job to finish.
- Examples:
- cd; ls execute one after another.
- (date;who;pwd)> logifile will redirect all the output from three commands to a filenamed logfile.
- sort file | lp will first sort a file and then print it.
- alias [options] [name[='command']] will let you create your own commands. i.e.
- let expressions is syntax of let statement.
- for x[in list] do commands done is syntax for for do loop.
- function name {commands;} is the syntax of a function which can be called from anywhere in program.
- if condition1 then commands1 elif condition2 then commands2 ... ... ... else commands3 fi
Ksh shell (Korn).
Ksh or Korn shell is widely used shell.
Csh or C shell
csh is second most used shell.
Echo command
echo command in shell programming.
Line command.
line command in shell programming.
Sleep command.
sleep command in shell programming.
Test Command.
test command in shell programming.
back to top of Shell programming.
back to top of page
<!-- shell programming ends here --> <!-- communications starts here -->
,
,
,
,
,
,
and
.
- Options
- -bn process lines using n-bit characters (7 or 8).
- -cname Search UUCP's device file and select local area network that matches name.
- -d Prints diagnostics.
- -e sends even parity data to remote system
- -lline communicate on this device (line=/dev/tty001, etc)
- -n prompts for a telephone number.
- -sn set transmission rate to n(e.g 1200,2400,9600, BPS)
- Destination
- telno is the telephone number of the modem to connect to.
- system is call the system known to uucp.
- aadr is an address specific to LAN.
- options
- -d enable debugging.
- -g disable filename globbing.
- -i turn off interactive prompts.
- -v verbose on. show all responses from remote server.
- options
- -8 will allow 8 bit data to pass, instead of 7-bit data.
- -e c will let you use escape character c.
- -l user will let you to login as user to remote host, instead of same as local host.
- Options
- -d will append the date to the logfile.
- -F user will forward mail to user when unable to send mail to mailfile.
- -l logfile will record in the logfile the names of senders who received automatic reply.
- -m mailfile will save received messages in mailfile.
Write command will initiate an interactive conversation with user. Syntax is
write user tty
back to top of communications commands
back to top of page
<!-- communications ends here --> <!-- storage commands start here -->
,
,
,
,
,
.
- Options
- -bn limit the number of bits in coding to n.
- -c write to standard output (do not change files).
- -f compress conditionally, do not prompt before overwriting files.
- -v Print the resulting percentage of reduction for files.
- It has three flags, -i, -o, -p
- cpio -i [options] [patterns]
- cpio -i copy in files who names match selected patterns.
- If no pattern is used all files are copied in.
- It is used to write to a tape.
- Options
- -a reset access times of input files.
- -A append files to an archive (must use with -o).
- -b swap bytes and half-words. Words are 4 bytes.
- -B block input or output using 5120 bytes per record.
- -c Read or write header information as Ascii character.
- -d create directories as needed.
- -l link files instead of copying.
- -o file direct output to a file.
- -r rename files interactively.
- -R ID reassign file ownership and group information to the user's login ID.
- -V print a dot for each file read or written.
- -s swap bytes.
- -S swap half bytes.
- -v print a list of filenames.
- Options
- 0-9 This number is dump level. 0 option causes entire filesystem to be dumped.
- b blocking factor taken into argument.
- d density of tape default value is 1600.
- f place the dump on next argument file instead of tape.
- This example causes the entire file system (/mnt) to be dumped on /dev/rmt/c0t0d0BEST and specifies that the density of the tape is 6250 BPI.
- for more info type man dump at command line.
- Options
- - Print number of times each byte is used, relative frequency and byte code.
- -f Force the pack even when disk space isn't saved.
- To display Packed files in a file use pcat command
pcat filename.z - To unpack a packed file use unpack command as unpack filename.z .
Examples:
tar cvf /dev/rmt/0 /bin /usr/bin creates an archive of /bin and /usr/bin, and store on the tape in /dev/rmt0.
tar tvf /dev/rmt0 will list the tape's content in a /dev/rmt0 drive.
tar cvf - 'find . -print' > backup.tar will creates an archive of current directory and store it in file backup.tar.
- Functions:
- c creates a new tape.
- r append files to a tape.
- t print the names of files if they are stored on the tape.
- x extract files from tape.
- Options:
- b n use blocking factor of n.
- l print error messages about links not found.
- L follow symbolic links.
- v print function letter (x for extraction or a for archive) and name of files.
- mt for HP-UX accept following commands
- eof write count EOF marks.
- fsf Forward space count files.
- fsr Forward space count records.
- bsf Backward space count files.
- bsr Backward space count records.
- rew Rewind tape.
- offl Rewind tape and go offline.
- eod Seek to end of data (DDS and QIC drives only).
- smk Write count setmarks (DDS drives only).
- fss Forward space count setmarks (DDS drives only).
- bss Backward space count setmarks (DDS drives only).
- Examples
back to top of storage commands
back to top of page
<!-- storage commands end here --> <!-- system status commands start here -->
at, chmod,chgrp, chown,crontab,date, df,du, env, finger, ps,ruptime, shutdwon,stty, who.
#!/bin/ksh
who | wc -l
echo "are total number of people logged in at this time."
30
are total number of people logged in at this time.
- Options:
- -f file will execute commands in a file.
- -m will send mail to user after job is completed.
- -l will report all jobs that are scheduled and their jobnumbers.
- -r jobnumber will remove specified jobs that were previously scheduled.
ls -la cal.txt
- Options:
- -h will change the group on symbolic links.
- -R recursively descend through directory changing group of all files and subdirectories.
- Options
- -h will change the owner on symbolic links.
- -R will recursively descend through the directory, including subdirectories and symbolic links.
Minutes 0-59
Hour 0-23
Day of month 1-31
month 1-12
Day of week 0-6 (0 is sunday)
25 22 15 * 0 /usr/local/bin/backup_jobs
Date command.
Date displays todays date, to use it type date at prompt.
Sun Dec 7 14:23:08 EST 1997
is similar to what you should see on screen.
- Options
- -b will print only the number of free blocks.
- -e will print only the number of free files.
- -f will report free blocks but not free inodes.
- -F type will report on an umounted file system specified by type.
- -k will print allocation in kilobytes.
- -l will report only on local file systems.
- -n will print only the file system name type, with no arguments it lists type of all filesystems
Du command.
du command displays disk usage.
Env command.
env command displays all the variables.
Finger command.
finger command.
- options.
- -a Lists all processes in system except processes not attached to terminals.
- -e Lists all processes in system.
- -f Lists a full listing.
- -j print process group ID and session ID.
Ruptime command.
ruptime command tells the status of local networked machines.
ruptime options
- options.
- -a include user even if they've been idle for more than one hour.
- -l sort by load average.
- -r reverse the sort order.
- -t sort by uptime.
- -i sort by number of users.
- options.
- -gn use a grace-period of n seconds (default is 60).
- -ik tell the init command to place system in a state k.
- -y suppress the default prompt for confirmation.
- Modes
- 0 hang up phone.
- n set terminal baud.
- erase keyname, will change your keyname to be backspace key.
- Options
- -a use all options.
- -b Report information about last reboot.
- -d report expired processes.
- -H print headings.
- -p report previously spawned processes.
- -u report terminal usage.
back to top of systemstatus commands
back to top of page
<!-- system status commands end here --> <!-- advance commands start here -->
Put advance commands utilities, redirection, etc here.
Något som saknas?
Tycker du att ovanstående lista är ofullständig? Låt mig i så fall få veta det.
Nya kommentarer
4 tim 58 min sedan
16 tim 32 min sedan
19 tim 42 min sedan
5 dagar 16 tim sedan
2 veckor 4 dagar sedan
2 veckor 4 dagar sedan
3 veckor 1 dag sedan
3 veckor 1 dag sedan
3 veckor 4 dagar sedan
3 veckor 4 dagar sedan