Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
34 views

Command Linux

The document provides examples of using AWK commands in Unix to perform various tasks: 1. Renaming files within a directory by replacing a substring using AWK, SED and the shell. 2. Removing only files in a directory listing using AWK and RM. 3. Removing only directories in a listing using AWK and RM. 4. Killing processes by name using AWK and KILL. The second document lists 15 important Unix commands, including MAN, CD, LS, CP, MV, RM, CAT, MORE, SCP, TAR, GREP, FIND, TAIL, HEAD, and VI. It provides brief descriptions and examples of using each

Uploaded by

ste_fanny23
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Command Linux

The document provides examples of using AWK commands in Unix to perform various tasks: 1. Renaming files within a directory by replacing a substring using AWK, SED and the shell. 2. Removing only files in a directory listing using AWK and RM. 3. Removing only directories in a listing using AWK and RM. 4. Killing processes by name using AWK and KILL. The second document lists 15 important Unix commands, including MAN, CD, LS, CP, MV, RM, CAT, MORE, SCP, TAR, GREP, FIND, TAIL, HEAD, and VI. It provides brief descriptions and examples of using each

Uploaded by

ste_fanny23
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

About AWK Command in Unix

1. Renaming within the name:


ls -1 *old* | awk '{print "mv "$1" "$1}' | sed s/old/new/2 | sh

(although in some cases it will fail, as in file_old_and_old) 2. remove only files:


ls -l * | grep -v drwx | awk '{print "rm "$9}' | sh

or with awk alone:


ls -l|awk '$1!~/^drwx/{print $9}'|xargs rm

Be careful when trying this out in your home directory. We remove files! 3. remove only directories
ls -l | grep '^d' | awk '{print "rm -r "$9}' | sh

or
ls -p | grep /$ | wk '{print "rm -r "$1}'

or with awk alone:


ls -l|awk '$1~/^d.*x/{print $9}'|xargs rm -r

Be careful when trying this out in your home directory. We remove things! 4. killing processes by name (in this example we kill the process called netscape):
kill `ps auxww | grep netscape | egrep -v grep | awk '{print $2}'`

or with awk alone: ps auxww | awk '$0~/netscape/&&$0!~/awk/{print $2}' |xargs kill


Posted by naani at 2:52 AM 1 comments

The 15 Most Important UNIX commands


The 15 Most Important UNIX commands 1. man - show manual for a command, example: man ls hit q to exit the man page. 2. cd - change directory, example: cd /etc/ 3. ls - list directory, similar to dir on windows. example: ls /etc, use ls -l /etc to see more detail 4. cp - copy a file or directory, example: cp source dest if you want to copy a directory use the -R option for recursive: cp -R /source
/dest

5. mv - move a file, example: mv source dest 6. rm - remove a file, example: rm somefile to remove a directory you may need the -R option, you can also use the -f option which tells it not to confirm each file: rm -Rf /dir 7. cat - concatenate, or output a file cat /var/log/messages 8. more - outputs one page of a file and pauses. example: more /var/log/messages press q to exit before getting to the bottom. You can also pipe to more | more from other commands, for example ls -l /etc | more 9. scp - secure copy, copies a file over SSH to another server. example:scp /local/file user@host.com:/path/to/save/file

10. tar - tape archiver, tar takes a bunch of files, and munges them into one .tar file, the files are often compressed with the gzip algorithm, and use the .tar.gz extension. to create a tar tar -cf archive.tar /directory, then to extract the archive to the current directory runtar -xf archive.tar to use gzip, just add a z to the options, to create a tar.gz: tar -czf archive.tar.gz /dir to extract it tar -xzf archive.tar.gz 11. grep - pattern matcher, grep takes a regular expression, or to match a simple string you can use fast grep, fgrep failure /var/log/messages, I'm usually just looking for a simple pattern so I tend to use fgrep more than regular grep. 12. find - lists files and directories recursively on a single line, I usually pipe grep into the mix when I use find, eg: find / | fgrep
log

13. tail - prints the last few lines of a file, this is handy for checking log files tail /var/log/messages if you need see more lines, use the -noption, tail -n 50 /var/log/messages you can also use the -f option, which will continuously show you the end of the file as things are added to it (very handy for watching logs) tail -f
/var/log/messages

14. head - same as tail, but shows the first few lines the file 15. vi - text editor, there are several text editors such as emacs, and nano, but vi is usually installed on any server so its a good one to learn. To edit a file type vi file to edit a line press Esc i then to save changes and exit use Esc wq, or to quit without saving use Esc q!. There are a million other commands, but that will enable you to edit files at a basic level.

You might also like