User Tools

Site Tools


Linux Commands

Command Function
cd {/folder/} cd (change directory), changes the current directory to folder
pwd shows current directory
ls shows all files and folders in the current directory in one line → confusing)
ll = ls –al → shows all files and folders + owner + size, 1 item each line
alias shows alias like „..“ for „cd ..“
cat {textfile} displays the full file
tail [-f -n 20] {file} displays the last 20 lines of the file – extension „–f“ refreshes the file, extension „–n 20“ displays the last 20 lines
head {file} same as tail but it displays the first lines
touch {file} create a file / refresh the timestamp
chmod [777 or +rwx] {file} change rights of a file
chown {user}:{group} {file or directory} [–R] change owner and group, -R changes the complete directory including files and subdirectorys
useradd [–m] add a user (-m creates a homedir)
groupadd add a group
cp {source} {target} [-r -a] copy data, -r copy directory, -a keep the rights
mv {source} {target} move file or directory
rm [–r] {file or folder} removes a folder with all data in it / rmdir only removes empty folders
cut [–d] “:” [-f] 1,3 : is the delimiter and 1 and 3 are the columns
echo “ ” > deletes the entries of a textfile
which sutp shows path of sutp
echo $? 0 = success of the last command
env run a program in a modified environment
uptime shows how long your machine is running
mkdir [–p] {/abc/abc} create a directory including a subdirectory
rpm [–ivh] install a rpm file (install verbose hash)
mount /dev/{cdrom, sr, hdc or tabtab} mount something
df -h diskfree lists your diskspace
dpkg -l | less shows all apps installed with apt-get
source {file} evaluates a file
ps [-aux] | grep '[p]erl' look up the perl process but dont show the grep “perl” process
ln -s {source} {target} symlink
cat /etc/*-release shows the linux distribution (SLES/Ubuntu etc)
find <PATH> -name “<FILENAME>” finds a file in path
history | grep xyz finds xyz in the last executed commands
zless /var/log/xyz.1.gz open packed logfiles
zless, zmore, zcat, zgrep open gzipped files without extraction
locate myscript lists all paths to files named myscript
ip addr list dev eth0 lists all ips, including virtual ips
echo $0 shows the current running process (in script)/ shows the running shell (in shell) (csh,bash,etc..)
echo $SHELL shows the default shell (csh,bash,etc..)
rsync -avzh /tmp/. copy /home to /tmp via rsync
wget -r ftp://<USER>:<PASS> copy / to current folder via wget
echo -e '\e[0;41m' set backgroundcolor red for your current shell
time /any/ displays the execution time
mtr dynamic ping/traceroute
nl shows script with numbered lines
curl display your external ip address
curl display a “whois” for your ip address
tree display files and folders as a tree
pstree display running processes with children as a tree
<space> rm secretfile this command will not be recorded in history
stat file.txt displays info of the file
while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;done & display the time on the top right corner in shell
echo "test" | mailx -s "Test mail" -S "smtp=<RELAY>" -r "<TO>" "<FROM>" Send mails via different SMTP without changing your postfix config
tar cfvz <archive>.tgz <dir/file> compress files to tgz
tar -xzfv <archive> decompress tgz to current dir
tar -xvjf <archive>.tar.bz2 <archive> decompress bz2 to current dir
tar -tvf <archive>.tar list files in tar
tar -xvf <archive>.tar home/foo/bar extract /home/foo/bar from the tar (NO LEADING SLASH /)
last -w displays the full name instead of only 8 chars
lsscsi -v lists the scsi device id and its partition
ypcat passwd list all users from the nis masterserver
ypwhich list your nis masterserver
find /tmp -type f -atime +30 -delete delete files in /tmp with no access in the last 30 days
dpkg --print-architecture show cpu architecture (amd64/i386/...) (debian/ubuntu only)
nmap -sL <IP like 192.168.178.*> List all hosts in the given IP-range
yes | yum install <package> submit yes - also works for other commands
du -hs * | sort -h | head show files by size and sort by size

Save textfile with password (VIM)

Command Function
vim -x <file> open file and set password
vim <file> open file and enter password after it was set

FTP Client

Command Function
ftp -i start client without corfirmation needed
get file.txt download file.txt
mget * download all files
put file.txt upload file.txt
mput * upload all files
ls -al show files in current folder
cd <PATH> change directory
lcd <PATH> change local directory

If you want to create a backup or copy your website, you might want to archive your files before transfer. Check the following script which does this Github - abdulawal39/ZipCF

Copy the .zip to your targetserver and execute a php file (eg. with the following code

<?php system('unzip <yourzipfile>.zip'); ?>


Problem Solution
put /tmp/files.tgz
local: /tmp/files.tgz remote: /tmp/files.tgz
200 PORT command successful
550 /tmp/files.tgz: No such file or directory
lcd /tmp/
cd /path/on/ftp
put files.tgz

SLES Commands

Zypper Cheat Sheet

Command Function
zypper ref Refresh repositorys
zypper up Update packages
zypper in <PACKAGE> Install PACKAGE
zypper info <PACKAGE> Shows the repository with PACKAGE
zypper lr List repositorys
zypper ar <REPOURL> Add repository via REPOURL
zypper mr -e <REPO> Activate existing REPO

Redhat Commands

Yum Cheat Sheet

Command Function
yum list all Show all available and installed packages
yum search <PACKAGE> Find info about [Package]
yum repolist Show enabled repositorys
yum clean all Clean all packages and meta data from cache
yum update Update all installed packages
yum update <PACKAGE> Update PACKAGE
yum reinstall <PACKAGE> Reinstall PACKAGE
yum remove <PACKAGE> Remove PACKAGE
yum downgrade <PACKAGE> Downgrade package to earlier version
yum --disablerepo=“*” --enablerepo=“my-repo” update Only update software of repository “my-repo”

Ubuntu/Debian Commands

Command Function
apt-cache search [Package] search for [Package] (example nano)
apt-get install [Package] installs [Package]
apt-get update update sources.list/repository
apt-get upgrade update all installed packages
apt-get remove [Package] remove [Package]
apt-get autoclean remove software without sources
apt-get autoremove remove unused dependencys
apt-get purge [Package] remove [Package] and its configs
apt-key list | grep expired list all expired keys
apt-key adv --keyserver hkp:// --recv <KEY> update a key (key = 1024D/1234A5B6)
apt-key adv --keyserver-options http-proxy=http://PROXYIP:8080 --keyserver hkp:// --recv <KEY> update a key with proxy
apt-key adv --keyserver --recv-keys <PUBKEY> add a key (key = NO_PUBKEY A12B3CD456789E0F
apt-mark hold [Package] hold back [Package]
apt-mark unhold [Package] remove hold back from [Package]
apt-mark showhold show held back packages
dkpg --install [Package.deb] installs offline packages
aptitude install [Package] installs [Package] alt. apt-get
service [Service] start/stop start/stop a service (rc for Suse)


dpkg -l | less shows all apps installed with apt-get
dpkg -l | grep <package> shows all apps installed with apt-get by packagename

What does "ii" mean?

man dpkg-query

The first three columns of the output show the desired action, the package status, and errors, in that order.

Desired action:

            u = Unknown
            i = Install
            h = Hold
            r = Remove
            p = Purge
Package status:

            n = Not-installed
            c = Config-files
            H = Half-installed
            U = Unpacked
            F = Half-configured
            W = Triggers-awaiting
            t = Triggers-pending
            i = Installed
Error flags:

           <empty> = (none)
            R = Reinst-required


Reset all:

echo -e "\e[0mNormal Text"


Escape characters:



echo -e "\e[31mHello World\e[0m"
echo -e "\033[31mHello\e[0m World"

Colorcode Code Description
39 echo -e “Normal Text \e[39mNormal Text” default color
30 echo -e “Normal Text \e[30mBlack” black
31 echo -e “Normal Text \e[31mRed” red
32 echo -e “Normal Text \e[32mGreen” green
33 echo -e “Normal Text \e[33mYellow” yellow
34 echo -e “Normal Text \e[34mBlue” blue
35 echo -e “Normal Text \e[35mMagenta” magenta
36 echo -e “Normal Text \e[36mCyan” cyan
37 echo -e “Normal Text \e[37mLight gray” light gray
90 echo -e “Normal Text \e[90mDark gray” dark gray
91 echo -e “Normal Text \e[91mLight red” light red
92 echo -e “Normal Text \e[92mLight green” light green
93 echo -e “Normal Text \e[93mLight yellow” light yellow
94 echo -e “Normal Text \e[94mLight blue” light blue
95 echo -e “Normal Text \e[95mLight magenta” light magenta
96 echo -e “Normal Text \e[96mLight cyan” light cyan
97 echo -e “Normal Text \e[97mWhite” white/ mostly default...
Colorcode Code Description
49 echo -e “Normal Text \e[49mNormal Text” default color
40 echo -e “Normal Text \e[40mBlack” black/ mostly default...
41 echo -e “Normal Text \e[41mRed” red
42 echo -e “Normal Text \e[42mGreen” green
43 echo -e “Normal Text \e[43mYellow” yellow
44 echo -e “Normal Text \e[44mBlue” blue
45 echo -e “Normal Text \e[45mMagenta” magenta
46 echo -e “Normal Text \e[46mCyan” cyan
47 echo -e “Normal Text \e[47mLight gray” light gray
100 echo -e “Normal Text \e[100mDark gray” dark gray
101 echo -e “Normal Text \e[101mLight red” light red
102 echo -e “Normal Text \e[102mLight green” light green
103 echo -e “Normal Text \e[103mLight yellow” light yellow
104 echo -e “Normal Text \e[104mLight blue” light blue
105 echo -e “Normal Text \e[105mLight magenta” light magenta
106 echo -e “Normal Text \e[106mLight cyan” light cyan
107 echo -e “Normal Text \e[107mWhite” white


echo -e “Normal Text \e[1mBold” bold
echo -e “Normal Text \e[2mDim” dim/ darker text
echo -e “Normal Text \e[4mUnderlined” underlined
echo -e “Normal Text \e[5mBlink” blink text/ doesnt work with most terminals
echo -e “Normal Text \e[7minverted” invert foreground and background colors
echo -e “Normal Text \e[8mHidden” hide text

More color stuff


Command Function
apt-get moo Try it out ;)
aptitude moo Try it out and add aptitude -v[vvvvv] moo ;)

linux/general/basics.txt · Last modified: 2019/12/23 15:43 by lunetikk