My Bash-Aliases

Hi folks!

Of course I like GUIs and I like KDE and graphical configuration-applications etc. But I am using the CLI (with bash and Yakuake) for many tasks like file-management, compilation, etc. Sometimes it may be even less effective than Dolphin or something like that, but it is quite useful and I got used to it. I am using a lot of aliases (or one-line-bash-script) I want to share with you. I admit that I do not use all of them, but I try to. ;)


alias ntar="tar -cf"
alias gz="tar -zcvf"
alias bz="tar -jcvf"
alias zp="zip"
alias ugz="tar -zxf"
alias ubz="tar -jxf"
alias utar="tar -xf"
alias uzp="unzip"
alias ltar="tar -tf"
alias lbz="tar -jtf"
alias lgz="tar -ztf"
alias lzp="unzip -l"
alias llz="tar --lzma -tf"
alias ulz="tar --lzma -xf"
alias lz="tar --lzma -cvf"

Show the entries of archives and create or unpack them, easier to memorize than “tar r

LANG=en_EN.UTF-8 g++ -c -Q $2 --help=optimizers > /tmp/O3-opts
LANG=en_EN.UTF-8 g++ -c -Q $1 --help=optimizers > /tmp/O2-opts
diff /tmp/O2-opts /tmp/O3-opts | grep enabled
rm /tmp/O2-opts /tmp/O3-opts

Process management

alias pr="ps -A | grep $1" # all processes matching the parameter
alias out="\$@ 2>&1" # print stderr to stdout
alias en="LANG=en_EN.UTF-8 \$@" # sometimes I do not want to have German translations, especially for bug-reports etc.

Some commands are too “complicate” for an alias:
quiet (suppress output):

$@ &> /dev/null

mute (start an application in the background silently):

echo "$@"
"$@" &> /dev/null &

mk (start an application using kdeinit4_wrapper):

#!/usr/bin/env ruby
pwd = Dir.pwd
cmd = "kdeinit4_wrapper " + ARGV[0]
for i in 1..(ARGV.size - 1)
        if ARGV[i][0] != "/"[0] && ARGV[i][0] != "~"[0]
                a = pwd + "/" + ARGV[i]
                ARGV[i] = a if File.exists? a
        cmd += " \"" + ARGV[i].gsub('"', '\"') + "\""
puts cmd

quitapp (quit an application):

ps -A | grep $1
echo "Try to quit using DBus..."
echo `kquitapp $1` > /dev/null
sleep 4
echo "Try to terminate..."
echo `killall -SIGTERM $1` &> /dev/null
sleep 1
echo "KILL!"
echo `killall -SIGKILL $1` &> /dev/null

restart (restart an application):

~/.script/ $1
~/.script/ kdeinit4_wrapper $@

suppress (continue execution after a failure):

echo `$@`

File management

alias s=less # show
alias e="mk kwrite" # editor, I noticed that I was using vi just because of the short command, that is why I have added s and e
alias d="du -sh" # size
alias cs='cd $1 && ls'
alias ms='mkdir $1 && cd $1'
alias kc=kioclient
alias ke="kfmclient exec " # open the files using the default application
alias g.="cd .."
alias g..="cd ../.."
alias g...="cd ../../.."


touch $1
mk.rb kwrite $1


echo $@ to trash
kioclient mv $@ trash:/


cp $1 /tmp/tempswap$(basename $1)
cp $2 $1
mv /tmp/tempswap$(basename $1) $2


ls -a | grep $@


alias adjusttime="sudo /usr/sbin/sntp -P no -r && echo \"New date: \`date\`\""
alias reset-networkmanager="sudo rm /var/lib/NetworkManager/NetworkManager.state"

chrootx (that is how chroot should work):

mount -o bind /proc $1/proc
mount -o bind /dev $1/dev
mount --bind /etc/hosts $1/etc/hosts
mount --bind /etc/resolv.conf $1/etc/resolv.conf
chroot $1 /bin/bash


sudo echo "Hibernate!"
kscreenlocker --forcelock &
sleep 3
sudo s2disk /dev/sda2

I had found options for kdmctl for shutting down the system, have to look them up again…


Try it yourself (alsa active, jack not active, espeak installed):

alias randsound="cat /dev/urandom | espeak --stdout | aplay"
alias randsoundde="cat /dev/urandom | espeak --stdout -v german | aplay"
alias reallyrandsound="cat /dev/random | espeak --stdout | aplay"
alias randreallysound="sudo cat /dev/urandom > /dev/dsp"

Have fun!

The User

6 Responses to “My Bash-Aliases”

  1. ABCD Says:

    To simplify your aliases a bit, the latest versions of GNU tar have a “-a” option for -c that auto-detects the compression algorithm from the filename. For instance “tar -caf foo.tar.gz …” will create a gziped tarball, while “tar -caf foo.tar.xz …” will create a xz-compressed tarball. Also, for everything else (extraction, listing, etc.), tar can autodetect the compression already used, so “tar -xf file.tar.bz2″ Just Works™.

  2. Ryan Says:

    You need to discover atool:

    Then you only need three commands: aunpack for extracting any type of archive, apack for creating any kind of archive, and als for listing the contents of any kind of archive.

  3. Alex Says:

    Regarding cmake: “-DCMAKE_PREFIX=/usr” , what is this good for ?
    Without checking, I think there is no such variable.
    CMAKE_INSTALL_PREFIX for the install location, and CMAKE_PREFIX_PATH for additional search directories.


  4. Ivan Says:

    In zsh, you can set it so that for unpacking, you only need to type a filename – like when executing a program:
    And it will be extracted.

    I’m not sure whether bash sports a similar feature, but I guess it is worth looking into.


  5. Artem S. Tashkinov Says:

    1. Your tar aliases are just plain awful and useless, nowadays tar automatically understands which archiver to use when unpacking or packing files:

    `tar xf archivename` unpacks any .tar{.bz2|gz|xz|} archive
    `tar caf archivename.tar.gz files_to_archive` automatically uses the appropriate archiver

    Note that even “-” (hyphen) is not required.

    2. alias pr=”ps -A | grep $1″ # all processes matching the parameter

    Discover pgrep -f

    Read the manuals sometimes before inventing the bicycle :)

  6. The User Says:

    Hmm, historical reasons, I think, have not touched it since years. :D

    Maybe I should give zsh a try, have heard some nice things about it. atool is maybe as obsolete as my tar-aliases, but -a really works, yeah, thanks. :D

Leave a Reply

XHTML: Use <blockquote cite="name"> for quotations, <pre lang="text    ∨ cpp-qt ∨ cpp ∨ bash ∨ other language"> for code, [latex] for formulas and <em> for em. Contact me if the comment does not get published, it may have accidentally been marked as spam.

Anti-Spam Quiz: