8jan11
COMMAND LINE COMMANDS






Terminal C
ommands
Compilation - Updated
(Here are those commands I have ever used)

Debian - should work on most distros though:

Files/Directories:


Files:
List files:
ls
dir

Create file:

touch
Delete file:
rm
Copy file:
cp
Move file:
mv
Display content of file:
cat
less
tail

Directories:
Create directory:
mkdir
Delete directory:
rm -r
rm -rf
Delete empty directory:
rmdir

Copy directory:
cp -r dir1 dir2


Create symbolic/soft links:

ln -s destination/file destination/link


Archives:

Extract filename.tar:
tar -xvf filename.tar
create filename.tar:
tar -cvf filename.tar filename

Extract filename.tar.gz:
tar -xvzf filename.tar.gz
create filename.tar.gz:
tar -czpf /path/filename.tar.gz /path/file(s)-to-archive

Extract filename.tar.bz2:
tar jxvf filename.tar.bz2
create filename.tar.bz2:
tar jxvf filename.tar.bz2 dir1 dir2 file1 file2 ...

Extract filename.rar:
unrar-free filename.rar
unrar x filename.rar

Extract filename.zip:
unzip filename.zip
Create filename.zip:
zip filename.zip dir1 dir2 ...



Package management:

Command line installation:
dpkg -i <filename.deb>
Apt:
Fix broken packages:
apt-get install -f
Search for packages:
apt-cache search <package-name>
Install packages without dependencies:
apt-get --no-install-recommends install <package-name>
Update:
apt-get update
Upgrade:
apt-get upgrade
apt-get dist-upgrade
Clean cache:
apt-get clean
apt-get autoclean


System info:

General:
uname -a
Network adapter:
ifconfig
iwconfig
Info hardware:

inxi
Info graphics:
inxi -G
Bus-system:
lspci
Bus-system verbose:
lspci -v
Network:
lcpci | grep -i net
Wireless adapter:
iwconfig


Network:

Network adapter:
lcpci | grep -i net
Wireless adapter:
iwconfig

Stop network:
ifdown eth0
Start network:
ifup wlan0

SSH - Secure Shell

Connect to remote machine:
ssh <user>@machine-ip
Copy file from local to remote machine with Secure Copy - scp:
scp /path/to/file
<user>@machine-ip:/path/to/destination
Copy file from remote to local machine:
scp <user>@machine-ip:/path/to/file /path/to/destination
Copy directory from local to remote machine:
scp -r /path/to/directory <user>@machine-ip:/path/to/destination


Users / Groups:

Users:
List users:
lastlog
cat /etc/passwd
Add user:
adduser <username>
Delete user:
deluser <username>
delete files:
deluser -r <username>
Change password:
passwd <username>
List group membership:
groups <username>
detailed:
id <username>

Groups:
List all groups:

id
cat /etc/group

(cat /etc/group |cut -d: -f1; cat /etc/passwd | cut -d: -f1)
Add group:
addgroup <groupname>
Delete group:
delgroup <groupname>
Add user to group:
adduser <username> <groupname>
gpasswd -a <user> <group>
e.g.:
gpasswd -a daniel kvm
Delete user from group:
gpasswd -d <user> <group>
Edit groups:
vim /etc/group


Manage rights:
Classic way (chmod, chown, chgrp) - a file/program can have only one owner/group:


special rights
owner
group
others
rights
sticky, suid, sgid
x, r, w
x, r, w x, r, w
octal

1, 4, 2
1, 4, 2 1, 4, 2
chmod

u=
g=
o=

example:
chmod 754 <file>
or:
chmod u=rwx,g=rx,o=r <file>


ACL - Access Control List (getfacl, setfacl) - refined user-rights management:
First make sure acl is installed and activated (kernel, fstab)!

Usage:
setfacl -m u:<user-x>:xrw,u:<user-z>:r,g:<group-a>:rw,g:<group-b>:r <file/program>

parameters:
-m (modifiy) assign/change rights
-d (default) assign default rights
-R (recursive) assign rights recursively
-b (remove all ACL-rights)
-k (remove default rights)


Daemons/Services:

Start daemon:
modprobe <daemon_name>
e.g.:
modprobe kvm
Services:
/etc/init.d/service start
/etc/init.d/service stop
e.g.:
samba, mysql, apache


Modules:

Blacklist modules:
 
vim /etc/modprobe.d/<module-name>.conf
e.g.:
 
vim /etc/modprobe.d/wlan.conf
add:
blacklist <module-name>
e.g.:
blacklist bcma
blacklist acer_wmi


Storage / Partitions:

Available disk space:
df -h

List drives:

fdisk -l
Mount drive:
mkdir /media/drive
mount /dev/sdh /media/drive
Unmount drive:
umount /media/drive

Grub:

Update grub:
update-grub


Arch Linux:

Package management:

AUR - Arch User Repository:
Extract:
tar -xvzf <package>
Make:
makepkg -s
Install:
pacman -U <package.pkg.tar.xz>

Pacman:
Search for packages in database:
pacman -Ss <package-name>
Search for installed packages on host:
pacman -Qs <package-name>
Install packages:
pacman -S <package-name>
System update & upgrade:
pacman -Syu
Clean pacman cache - not installed packages and old versions of installed packages:
pacman -Sc
Remove packages:
pacman -R
<package-name>
Remove packages with dependencies:
pacman -Rs <package-name>