Tải bản đầy đủ (.doc) (4 trang)

Những câu lệnh Linux thường dùng pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (89.31 KB, 4 trang )

commands to display file contents
cat pr more less
1. cat - conCATonate or display entire file contents
cat /etc/passwd
2. pr - format files with headings including the filename and page numbers
pr /etc/motd | lpr (formats the message-of-the-day file and
directs the output to the default printer)
3. more - display file contents one page at a time
cat /etc/passwd | more
is the same as:
more /etc/passwd
4. less - display file contents one page at a time
ls | less
keys used with the more and less commands:
up arrow key = up 1 line
down arrow key = down 1 line
spacebar = down 1 screen
b = back up 1 screen
q = quit
h = display help screen
commands to display file & directory attributes
ls pwd du find tree whereis
On a Linux file server used by several clients, there is a frequent need to find files,
modify files, share files and examine statistics about files. Linux has a number of very
useful commands for doing these kinds of tasks
1. ls - list directory contents
ls (ls with no options: list files in current directory)
ls -a (list hidden files - files that begin with "." character)
ls -l (long/detailed listing)
ls -l /etc (list files in a specific directory)
1


ls color (list files with colored highlighting)
color codes for files:
grey = regular file
dark blue = directory
light blue = symbolic link
green = executable
yellow = socket
brown = FIFO
commands to delete, copy, move & rename files & directories
cp mv rm mkdir
rmdi
r
cpio
On a Linux file server used by several clients, there is a frequent need to find files,
modify files, share files and examine statistics about files. Linux has a number of very
useful commands for doing these kinds of tasks
1. cp - copy file
cp passwd passwd_new
2. mv - move file
mv filename newfilename
3. rm - remove file
rm filename
4. mkdir - make directory
cd abc ; mkdir dir1 dir1/subdir
5. rmdir - remove empty directory
rmdir -p dir1/subdir (the -p option causes the removal of all
parent directories, not just the subdirectories, in the specified path)
6. cpio - copy directory structures from one directory to another, one file system to
another.
cpio - copy files (usually used with the "find" command).

Example of copying all the files from one directory to another:
2
cd /olddirectory (go to the directory that you want to copy)
find . -depth -print | cpio -padm /newdirectory
Note: doing this procedure from the root "/" directory will usually cause problems -
you will probably run out of space on the new directory since the "find" command
will probably end up copying the entire contents of several file systems into your
new directory, which will not fit of course.
You WILL have problems copying files from actively used file systems,
especially if you are copying the entire root file system or a database, etc.
The only safe way to copy files that may be in use is to insure that they are
NOT in use. You do this by running shutdown without the "-h" option. This
will put the system into single user mode. Then you can safely copy files that
might normally be in use by the OS or by some user application, like a DBMS
app (Oracle, MYSQL, and such). Normally, you would do this after hours
when it would not be an inconvenience for your users.
commands to search file contents
grep cmp comm diff file uniq wc
1. grep - get regular expression
in other words, search for strings of characters:
grep "/bin/sh" /etc/passwd (search for "/bin/sh" in the
password file)
grep -i root /etc/passwd (ignore upper/lower case)
2. cmp - conCATonate or display entire file contents.
cmp /etc/passwd
3. comm - display duplicate or unique lines between two sorted files in 3 column
format.
comm /etc/passwd /etc/passwd.old
4. diff - display the lines that differ between two files. differing lins are displayed on
alternate lines with a "<" character prepended to lines from file1 and a ">" character

prepended to lines from file2.
diff /etc/passwd /etc/passwd.old
5. file - display the type of the file (ascii text, directory, c program, empty, executable
etc.)
file unknownfile
file * | grep directory

3
6. uniq - display duplicate or unique lines within a single sorted file.
uniq myfile.txt

7. wc - display the number of words, lines and characters in a file
wc myfile.html
8. SEE ALSO:
zgrep, zcomp, & zdiff
4

×