Cheat Sheets
From QwikITedia
Contents |
Grep
- Grep is a command line text search utility originally written for Unix
Search for a string in a file
$ grep "literal_string" filename
Case Sensitive search
$ grep -i "literal_string" filename
Check for string in multiple files with partial same name
$ grep "string" filenames*
Search a dir and sub dirs
$ grep -r "directoryname" *
Count occurrences in a file
$ grep -c "pattern" filename
Secure Copy(scp)
What is Secure Copy?
- scp allows files to be copied to, from, or between different hosts. It uses ssh(secure shell) for data transfer and provides the same authentication and same level of security as ssh.
Why I use it
- cos' its much faster than sftp
Examples
- Copy the file "bighairyfile.txt" from a remote host to the local host
$ scp your_username@remotehost.edu:bighairyfile.txt /some/local/directory
- Copy the file "bighairyfile.txt" from the local host to a remote host
$ scp bighairyfile.txt your_username@remotehost.edu:/some/remote/directory
- Copy the directory "bigdir-locationA" from the local host to a remote host's directory "bigdir-locationB"
$ scp -r bigdir-locationA your_username@remotehost.edu:/some/remote/directory/bigdir-locationB
- Copy the file "bighairyfile.txt" from remote host "host1.com" to remote host "host2.net"
$ scp your_username@host1.com:/some/remote/directory/bighairyfile.txt your_username@host2.net:/some/remote/directory/
- Copying the files "file1.txt" and "fileB.txt" from the local host to your home directory on the remote host
$ scp file1.txt fileB.txt your_username@remotehost.org:~
tARCHIVng
Extract a tar file
tar -xvf file.tar
tar -xvzf file.tar.gz
tar -xvjf file.tar.bz2
Archive a set of files
tar -cvf tarfile.tar /var/log/syslog /var/log/messages
Archive and compress (gzip) a set of files
tar -cvzf file.tar.gz /var/log/syslog /var/log/messages
Archive and compress (bzip2) a set of files
tar -cvjf file.tar.bz2 /var/log/syslog /var/log/messages
Display the content of a tar file
tar -tvf file.tar
tar -tvzf file.tar.gz
tar -tvjf file.tar.bz2
Replace a file in an existing tar file
tar -rvf tarfile.tar filetoreplace
Update a file in an existing tar file
tar -uvf tarfile.tar newfile