Darkland | net

Command Line Jive

Published on 5 September 2013 by Amanda
Caveats:
# <-- This is the root command prompt. It means run as root (or use sudo). I often tend to
be too cavalier to just be one of those sudo pussies!
$ <-- This is the unprivileged command prompt. It means run as an unprivileged user, like you.
[new group] [user] <-- These are not regular expressions
[D|d] [0-9][G] <-- These are regular expressions
Redirecting input/output:
stdin - 0 - Standard Input (usually keyboard or file)
stdout - 1 - Standard Output (usually screen)
stderr - 2 - Standard Error (usually screen)
ex.: command 2> /dev/null redirects error messages to special device /dev/null

Scale a video with ffmpeg: $ ffmpeg -i ./input.mp4 -vf scale=640:360 $HOME/Videos/output.mp4
How to hold a package at a specific version: sudo apt-mark hold package_name
Shred: $ shred -n 32 -v -u -z
Generate random character strings:$ cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 10The tr command constrains output to alphanumeric characters.
The fold command creates strings 10 columns wide.
The head command creates 10 strings.

Create a CDROM ISO from a directory on a hard drive: $ mkisofs -J -r -o [output.iso] [directory to be burned]
Get some info about a CD-ROM: $ isoinfo -d -i /dev/sr0
Create an ISO using info from isoinfo: $ dd if=/dev/sr0 bs=blocksize count=count of=/path/to/isoimage.iso
Get some information about an ISO image: $ isoinfo -d -i /apps/images/wxpvol_en.iso
Here, play with that... $ echo $(( `date +%Y` - 1964 ))
Using rsync: $ rsync -rvbpogt root@fembot:/apps/backups /mnt/external/
Where:
    -r recursive
    -v verbose
    -p preserve permissions
    -o preserve owner
    -g preserve group
    -t preserve time
All I ever really use is rsync -rac --progress [...]
addgroup quickie # addgroup -gid [New Group Number] [group name]
This will append [group name] to the list of groups [user] is a member of. The -a is significant. ALL GROUPS the user currently belongs to will be clobbered (removed from the user's group membership list) without it. For example, my current group membership is: andrew adm dialout cdrom plugdev lpadmin admin sambashare allaccess. Without the -a my group membership will be changed to only: [group name], whish is bad. # usermod -a -G [group name] [user]
This will find directories that are x GB in size. Where: [-h] is human-readable (12 GB instead of 12010400) $ du -h | grep [0-9][G]
This will find lines in a file that start with the letter s and end with the letter n: $ grep '^s.*n$' myfile
This will find lines in a file that start with either the letter R or c and end with the letter N: $ grep '^[R,c].*N$' myfile
This will search recursively, print the file name and line number, and match whole string/word: grep -rnw '/path/to/somewhere/' -e 'pattern'
Finding unused kernels on the system with sed: $ ls /boot/ | grep vmlinuz | sed 's@vmlinuz-@linux-image-@g' | grep -v `uname -r`
Using checkinstall to compile and install packages. sudo checkinstall --pkgname=ncmpcpp-x86 --pkgversion="0.7" --backup=no --default --deldoc=yes


Back