Site Tools


linux:scripts:basics

This is an old revision of the document!


Linux Commands

Command Function
cd /blabla/ cd (change directory), changes the current directory to blabla
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] displays the last 20 lines of the file – extension „–f“ refreshes the file, extension „–n 20“ displays the last 20 lines
head same a tail but it displays the first lines
touch [file] create a file / refresh the timestamp
chmod 777 [file] change rights of a file
chown user:group [directory] –R change owner and group, -R changes the complete directory including files and subdirectorys
useradd –m add a user
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 removes a directory with all data in it / rmdir only removes empty directorys
cut –d : -f 1,3 : is the delimiter and 1 and 3 are the columns
echo “ ” > test.sh 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 VMWaretools

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
apt-get upgrade update all installed packages
apt-get remove [Package] remove [Package]
apt-get purge [Package] remove [Package] and its configs
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)


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

Script

Commands

Command Function
#!/bin/bash
or
#!/bin/sh
shebang
VAR=var set VAR to var
$VAR inserts var whereever $VAR is placed
case - esac inserts case
if - fi inserts if

Troubleshooting

Interpreter error

Problem:
Running your script prompts interpreter error

Fix:
Open your script with vi and execute the following

 :set fileformat=unix 

Not enough rights

Problem:
Running your script requires more rights

Fix:
Make your script runable by executing the following code

chmod +x [scriptname].sh

linux/scripts/basics.1412162518.txt.gz · Last modified: 2017/03/01 12:50 (external edit)