User Tools

Site Tools


shell

Shell commands

A nice cheatsheet is available here

Get disk space usage

df -h

Get a clean arborescence of a projet

tree -a -I '.git' -L 3

Get the size of elements in the current folder

du -chs *

Find largest directories in current path

du -ck | sort -nr | head -n 10

Get working path

pwd

Get system infos

uname -a
lsb_release -a
grep -ril mot_a_chercher .

Restart a service

# examples :
sudo /etc/init.d/nom_du_service restart
sudo service nom_du_service restart
apache2ctl restart

Delete files older than 30 days, in the current folder

find . -maxdepth 1 -ctime +29 -exec rm {} \;

Delete ".svn" folders, from current path

find . -name ".svn" -type d -exec rm -rf {} \;

Get "png" files, from current path

find . -iname '*.png'

Count nb of files, in the current path

find . -type f | wc -l

Search a term in a serie of files

grep -nri (my_term) ~/logs_*

Compress dir

tar -zcvf tar-archive-name.tar.gz source-folder-name

Uncompress dir

tar -zxvf tar-archive-name.tar.gz source-folder-name

Anacron (daily)

sudo apt-get install anacron
sudo vim /etc/cron.daily/newfile
( | tee -a /var/log/anacron_newfile.log)

Auto upgrade sur Anacron (daily)

~ cat /etc/cron.daily/auto-upgrade 
#!/bin/sh

date | tee -a /var/log/anacron_auto-upgrade.log
apt-get -y update && apt-get -y upgrade | tee -a /var/log/anacron_auto-upgrade.log

Make a diff between 2 folders

diff -bur <folder1> <folder2>

Update root password

sudo passwd <username>

Add a user to sudoers

vim /etc/sudoers.d/{{ user }}-sudoer
{{ user }} ALL=(ALL:ALL) NOPASSWD: ALL

# or if you want to keep password protection (more secure) :
{{ user }} ALL=(ALL:ALL) ALL

Add a script to execute at startup

vim /etc/init.d/rc.local
{{ anything }}

Update default programs

sudo update-alternatives --all
sed -n 20,40p myfile

Zip / unzip a folder

zip -r myfile.zip mydir
unzip myfile.zip

# alternative : zip directly to the root folder
cd mydir/ && zip ../myfile.zip -r .

Execute a command in background

<any-command>  > /dev/null 2>&1 &

Security : Generate a GPG key

gpg --gen-key

Get a clean arborescence of a projet

tree -a -I '.git' -L 3
shell.txt · Last modified: 2020/05/02 09:34 (external edit)