====== Useful Linux Commands ====== The following is a list of useful commands that I've learned for Linux, but that I use so rarely, I tend to forget until I need them again. ===== CDROM / DVD commands ===== ==== Mount an ISO to the filesystem ==== Execute the following command: mount file.iso /cdrom -t iso9660 -o loop ====Creating a CD ISO==== To rip an entire normal data-cd (ISO filesystem) from a CD-ROM: dd if=/dev/cdrom of=my_cd_image.iso ====Making an ISO from a file system==== To create an iso using files in Linux: mkisofs -o image.iso path/ ====Burning a CDROM==== wodim dev=/dev/cdrw -v -data cd_image.iso wodim dev=/dev/cdrw -v -audio [wav files...] ====Burning a DVD==== To burn a DVD from the filesystem: growisofs -dvd-compat -input-charset=ISO-8859-1 -Z /dev/cdrom -R -J -pad "/path/to/source/dir/structure" =====Floppy Disk Commands ===== ====Creating a floppy image==== To create a blank floppy disk image: mkfs.msdos -C image.flp 1440 ====Mount a floppy image to the filesystem==== To mount a floppy image: mount -o loop image.flp /media/floppy1/ =====Video codec commands===== ====Transcoding to iPod and iPhone format==== To take a video file to a format usable by an iPod or an iPhone: ffmpeg -vcodec xvid -b 300 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac -ab 96 \ -i source_file.avi -s 320x240 -aspect 4:3 target_file.mp4 Take target_file.mp4 and import into iTunes, then sync with your device. =====Generic Bash===== ====Redirecting STDERR to a pipe in Bourne/BASH==== Passing *both* stdout and stderr to the pipe. 2>&1 | Passing only stderr to the pipe: exec 3>&1 2>&1 >&3 3>&- | 3>&- exec 3>&- =====Backups===== ====Running remote backups to tape with tar==== Use the following command to dump a directory structure to a remote tape drive: tar cv --rmt-command=/sbin/rmt --rsh-command /usr/bin/ssh -f :/dev/st0 --directory /path/to/source/dir --label "Label for backup" Use the following command to recover a directory structure from a remote tape drive: tar xv --rmt-command=/sbin/rmt --rsh-command /usr/bin/ssh -f :/dev/st0 Of course, as always with the tar command, one can specify the files/sub-directories to be recovered if one wishes. ==== rsync usage ==== Proper, recursive directory structure copy that preserves permissions, etc. Also can restart partial transfers, just execute the command again after a failure. $ rsync --partial --append --verbose --stats --progress --compress --rsh=/usr/bin/ssh --recursive --times --perms --links ===== Generic sysadmin stuff ===== ====Shutting down the monitor==== /usr/bin/xset dpms force off ====Mounting a SMB fileshare==== To mount a Windows or Samba SMB fileshare: mount -t cifs //ntserver/download -o username=user,password=myPassword /mnt/ntserver ==== top pipline for quick system state ==== Tweak the $8 == 'D' to look at different states of processes. top -b -n 1 | awk '{if (NR <=7) print; else if ($8 == "D") {print; count++} } END {print "Total status D: "count}' Example output top - 11:33:29 up 8 days, 18:00, 2 users, load average: 5.61, 5.35, 7.00 Tasks: 101 total, 1 running, 100 sleeping, 0 stopped, 0 zombie Cpu(s): 2.7%us, 1.9%sy, 0.0%ni, 78.0%id, 16.7%wa, 0.2%hi, 0.5%si, 0.0%st Mem: 1991292k total, 1975248k used, 16044k free, 56836k buffers Swap: 1150724k total, 36k used, 1150688k free, 1652024k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 334 root 20 0 0 0 0 D 0.0 0.0 5:16.26 kdmflush 959 root 20 0 0 0 0 D 0.0 0.0 4:35.89 jbd2/dm-2-8 1080 root 20 0 0 0 0 D 0.0 0.0 1:53.47 nfsd 1081 root 20 0 0 0 0 D 0.0 0.0 1:58.73 nfsd 1082 root 20 0 0 0 0 D 0.0 0.0 1:52.42 nfsd 1083 root 20 0 0 0 0 D 0.0 0.0 1:51.43 nfsd 1084 root 20 0 0 0 0 D 0.0 0.0 1:58.40 nfsd 1085 root 20 0 0 0 0 D 0.0 0.0 1:50.55 nfsd 1086 root 20 0 0 0 0 D 0.0 0.0 1:51.28 nfsd 1087 root 20 0 0 0 0 D 0.0 0.0 1:58.37 nfsd Total status D: 10 ==== rsyslog - remote host log containment ==== Place at the top of the /etc/rsyslog.d/50-default.conf :source, isequal, "router_address" /var/log/ & ~ ===== Networking ===== ==== ASN lookup via whois ==== $ whois -h v4.whois.cymru.com " -c -p 61.0.0.70" AS | IP | BGP Prefix | CC | AS Name 9829 | 61.0.0.70 | 61.0.0.0/20 | IN | BSNL-NIB National Internet Backbone ==== Routing ==== === Checking === cat /proc/sys/net/ipv4/ip_forward or sysctl net.ipv4.ip_forward === Enabling === On the fly: sysctl -w net.ipv4.ip_forward=1 To make it permanent, add the following to /etc/sysctl.conf: net.ipv4.ip_forward = 1 Run the following command: # sysctl -p /etc/sysctl.conf ==== pcap analysis ==== Wireshark CLI packet analyzer: tshark Example for processing Cisco netflow: tshark -r test.pcap -n -d udp.port==3010,cflow -V ===== X-windows Tricks ===== ==== Open Remote Desktop Environments ==== Open a second X-windows server on the local host xinit -- :1 In the xterm of the resulting desktop on the local host, SSH to the remote host ssh -X user@remotehost In the SSH session to the remote host, start gnome gnome-session Additional X-windows servers can be started on the local host with successive xinit commands using :2, :3, etc. Alternative desktop environments such as KDE can be used if desired. ==== Changing the primary monitor ==== Check to see the names of the attached outputs: xrandr --prop|egrep "VGA|DVI" Set the one desired: xrandr --output DVI-0 --primary