3 minutes
A Linux Commands Overview
Some useful terminal commands in Linux or OSX
-> List all cronjobs from all users and services (all existing)
for user in $(cut -f1 d: /etc/passwd); do crontab -u $user -l; done
-> For all users and services in /etc/passwd
for user in $(cut -f1 -d: /etc/passwd); do echo $user; crontab -u $user -l; done
-> A nicer list for each user in /etc/passwd
-> Find and delete 10 days old files in /tmp
find /tmp -ctime +10 -exec rm -rf {} +
-> Zip and Tar over SSH compression
Compresses/packs the archiveName
from any directory or file to a new file
# dir with zip (you might need to install this)
zip -r archiveName.zip /directory/to/compress
# decompress (extracts archiveName's content to the current folder (in place))
unzip archiveName.zip
# dir with tar
tar -cvf archive_name.tar /directory/to/compress
# decompress (extracts archiveName's content to the folder '/tmp')
tar -xvf archiveName.tar -C /tmp
# dir with tar and gzip compression
tar -czvf archiveName.tar.gz /path/to/dirOrFile
# decompress (extracts archiveName's content to the folder '/tmp')
tar -xzvf archiveName.tar.gz -C /tmp
# dir with tar and bzip2 compression
tar -jcvf archiveName.tar.bz2 /directory/to/compress
# decompress (extracts archiveName's content to the folder '/tmp')
tar -jzvf archiveName.tar.bz2 -C /tmp
-> Shop open ports
netstat -lntp
-> Show usage of port $NUMBER
here TCP protocol with port 9000
lsof -nP -i4TCP:9000 |grep LISTEN
-> Search | Find files
Where you are
find -name "*nginx*"
Or in a different, named folder
find /var/log -name "*nginx*"
-> Chmod - Change permissions
d rwx r-x r-x 6 User staff 204 17 Mai 15:30 vendor
^ ^^^ ^^^^----^^^^^
| ||| |||| |||||
| ||| -> belongs to "User" in the user-group "staff"
| ||| | || -> right to execute
| || | | -> right to write
| | | -> right to read
| -> directory
actually change:
chmod [-v] [-R [-L | -P]] mode file ...
verbose
recursive
[-L: symbolic links are followed]
[-P: don't follow symbolic links (default)]
Overview for modes / bitmatrix:
inputvalue | bitwise | shownrights | meaning |
---|---|---|---|
0 | 000 | — | no access |
1 | 001 | –x | execute |
2 | 010 | -w- | write |
3 | 011 | -wx | write / execute |
4 | 100 | r– | read |
5 | 101 | r-x | read / execute |
6 | 110 | rw- | read / write |
7 | 111 | rwx | read / write / execute |
Now set all files inside this folder to d - rwx r-x r--
:
user@computer $ chmod -R 754 vendor/
-> Chown - Change file | folder ownage
drwxr-xr-x 3 root staff 102 25 Mai 2016 .vim
^^^^--^^^^^ |||| |||||
-> belongs to user "root" in the user-group "staff"
Syntax for change-ownage ‘chown’:
chown [-v] [-R [-L | -P]] owner[:group] file ...
- See 'chown' above for declaration of arguments,
- owner means the users account name
- group is optional and means the name of 'his' user group
Now I want to change this belonging recursively to me, user:staff (with user’s group!):
User@computer /folder/where/vim/is $ su (or) sudo su
root@computer / # cd /folder/where/vim/is
root@computer /folder/where/vim/is # chown -R user:staff .vim
root@computer /folder/where/vim/is # [CTRL+D]
User@computer /folder/where/vim/is $ exit