Linux Commands
Linux Commands
Linux Commands
System Information
shutdown -h now
shutdown system
init 0
shutdown -r now
reboot
reboot
cd go to home directory
cd - go to previous directory
rm -rf dir1 dir2 remove two directories and their contents recursively
File Search
find / -name file1 search file and directory into root filesystem from '/'
find /usr/bin -type f -atime +100 search bynary files are not used in the last 100 days
find /usr/bin -type f -mtime -10 search files created or changed within 10 days
find / -name *.rpm -exec chmod 755 {} ; search files with '.rpm' extension and modify permits
Mounting a Filesystem
mount -t smbfs -o
username=user,password=pass //winclient/share mount a windows network share
/mnt/share
Disk Space
ls -lSr |more show size of the files and directories ordered by size
du -sh * | sort -rn show size of the files and directories sorted by size
rpm -q -a --qf '%10{SIZE}\t%{NAME}\n' | sort show space used by rpm packages installed sorted by
-k1,1n size (fedora, redhat and like)
groupmod -n new_group_name
rename a group
old_group_name
find / -perm -u+s view all files on the system with SUID configured
chmod g+s /home/public set SGID bit on a directory - similar to SUID but for
directory
Special Attributes on file - use "+" to set permissions and "-" to remove
rar a file1.rar file1 file2 dir1 compress 'file1', 'file2' and 'dir1' simultaneously
tar -cvf archive.tar file1 file2 dir1 create an archive containing 'file1', 'file2' and 'dir1'
rpm -ivh --nodeeps package.rpm install a rpm package ignoring dependencies requests
rpm -qa | grep httpd show all rpm packages with the name "httpd"
rpm -ql package_name show list of files provided by a rpm package installed
rpm -q package_name --whatrequires show list of dependencies required for a rpm packet
rpm -qf /etc/httpd/conf/httpd.conf verify which rpm package belongs to a given file
rpm -ivh
install a package built from a rpm source
/usr/src/redhat/RPMS/`arch`/package.rpm
yum clean all remove from the cache packages and headers files
dpkg -l | grep httpd show all rpm packages with the name "httpd"
cat file1 view the contents of a file starting from the first row
tac file1 view the contents of a file starting from the last line
Text Manipulation
cat file_test | [operation: sed, grep, awk, grep, syntax to elaborate the text of a file, and write result to
etc] > result.txt a new file
cat file_originale | [operazione: sed, grep, awk, syntax to elaborate the text of a file and append result
grep, etc] >> result.txt in existing file
grep Aug -R /var/log/* search string "Aug" at directory '/var/log' and below
sed '/ *#/d; /^ *$/d' example.txt remove comments and blank lines from example.txt
echo 'esempio' | tr '[:lower:]' '[:upper:]' convert from lower case in upper case
sed -e '1d' result.txt eliminates the first line from file example.txt
sed -n '/stringa1/p' view only lines that contain the word "string1"
sed -e 's/ *$//' example.txt remove empty characters at the end of each row
echo a b c | awk '{print $1,$3}' view the first and third column of a line
sort file1 file2 | uniq sort contents of two files omitting lines repeated
sort file1 file2 | uniq -u sort contents of two files by viewing only unique line
dos2unix filedos.txt fileunix.txt convert a text file format from MSDOS to UNIX
unix2dos fileunix.txt filedos.txt convert a text file format from UNIX to MSDOS
recode ..HTML < page.txt > page.html convert a text file to html
Filesystem Analysis
Format a Filesystem
SWAP Filesystem
Backup
rsync -az -e ssh --delete ip_addr:/home/public synchronize a local directory with a remote directory
/home/local via ssh and compression
rsync -az -e ssh --delete /home/local synchronize a remote directory with a local directory
ip_addr:/home/public via ssh and compression
dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr make a backup of a local hard disk on remote host via
'dd of=hda.gz' ssh
find /home/user1 -name '*.txt' | xargs cp -av find and copy all files with '.txt' extention from a
--target-directory=/home/backup/ --parents directory to another
find /var/log -name '*.log' | tar cv --files-from=- find all files with '.log' extention and make an bzip
| bzip2 > log.tar.bz2 archive
dd if=/dev/hda of=/dev/fd0 bs=512 count=1 make a copy of MBR (Master Boot Record) to floppy
dd if=/dev/fd0 of=/dev/hda bs=512 count=1 restore MBR from backup copy saved to floppy
CDROM
cdrecord -v gracetime=2 dev=/dev/cdrom -eject
clean a rewritable cdrom
blank=fast -force
mkisofs /dev/cdrom | gzip > cd_iso.gz create a compressed iso image of cdrom on disk
cd-paranoia -- "-3" rip first three audio tracks from a CD to wav files
route add -net 192.168.0.0 netmask 255.255.0.0 configure static route to reach network
gw 192.168.1.1 '192.168.0.0/16'
netstat -tup show all active network connections and their PID
mount -t smbfs -o
username=user,password=pass //winclient/share mount a windows network share
/mnt/share
IPTABLES - Firewall
iptables -t nat -A POSTROUTING -o eth0 -j configure a PAT (Port Address Traslation) on eth0
MASQUERADE masking outbound packets