Common Linux commands and syntax
Posted by Ryan on September 28, 2008 in Linux, Solaris
A list of commands and their syntax, some of which for some reason, seem to escape me only when I need it.
tar -cvf <archive name> <source directory> (create an archive from a directory)
rsync -auEv <source directory> <destination directory> (copy files locally from one location to another keeping all permissions and modification dates and Executibility)
rsync -auvEe ssh root@192.168.0.1:/home/me/folder1 /home/you (copies from another host using ssh and the remote user “root” to login and gain access to /home/me/folder1 and copy it locally to /home/you/folder1)
strace -p <pid> (run strace on a currently running process id number)
ssh -x <command> (provides additional information when running a command)
ssh -L 9999:192.168.0.1:3389 <username>@192.168.0.23 (creates a local port 9999 that will forward traffic through 192.168.0.23 via ssh to 192.168.0.1 port 3389. a.k.a encrypt your rdesktop session)
ssh -XC <username>@<destination ip or hostname> (remotely connect to a machine running sshd, also exporting your display and enabling compression)
iostat 1 100 (run iostat every second 100 times)
netstat -rn (show routing table, and don’t resolve names)
netstat -an (show all enabled ports and sockets on an operating system)
arp -a (show the current arp table)
dmidecode (show hardware information for your running system)
rpm -qPpl <rpm patch file name> (displays the files contained in a rpm patch file that is not installed)
rpm -qa –qf ‘%{name}%{version}%{release}%{arch}\n’ | egrep ‘<packagename>’ (lists the name, version, release and architecture information for all packages that match the <packagename> criteria)
rpm -ql <rpm package name> (displays all files are their locations that are associated with the package specified)
iptables -A INPUT -p tcp –dport 22 -s 192.168.0.2 -j DROP (creates a rule in memory that allows iptables to drop incoming ssh connections that originate from 192.168.0.2.) Add this to a start script to make this persistent!
setfacl -m d:u:bob:rw /home/bob (set a user acl with read/write access on the directory /home/bob)
free (show memory related information)
ldd /usr/bin/sshd (shows all shared libraries that the ssh daemon uses/requires)
find /etc -depth | cpio -pdmV /tmp/etcbackup (searches for everything listed in /etc (recursive) and sends the results to cpio, which in turn places all files in /tmp/etcbackup..this is much cleaner than cp -a..Also, you can add a “u” to the cpio to do this unconditionally.)
find /var -print | xargs du |sort -g (searches in /var and all sub directories (recursive) below for all files and puts them in numerical order according to their size.)
Subscribe
Follow comments by subscribing to the Common Linux commands and syntax Comments RSS feed.