Useful Command Line Scripts

Home / Coding / Useful Command Line Scripts

Below is a list of very common linux commands that any linux person should know by heart. From gzipping files, to running backups this is my personal cheat sheet

Compressing Files and Folders

Unzip 7z Archive

7za x myfiles.7z

gzip File

gzip -9 file

gzip Folder

tar -zcvf archive-name.tar.gz directory-name

Uncompress Gzip File

gzip -d file.gz

Remove Files and Folders

Removing a large number of files

If you’re getting this error:

/bin/rm: Argument list too long.

Use this command:

find . -type f -delete

Remove folder from SVN

rm -rf `find . -type d -name .svn`

Remove ._ files

find . -name "._*" -exec rm '{}' \; -print

Remove Dreamweaver Notes

rm -rf `find . -type d -name _notes`

Renaming Multiple Files

find . -name "*.jpg" -exec sh -c 'mv "$1" "${1%}.png"' _ {} \;

Clear Bash History

history -c

Reset you Gnome Toolbar

rm -rf .gnome .gnome2 .gconf .gconfd

Get the total size of a folder with subdirectories

du -ch | grep total

Transferring Files

Rsync local files to server

rsync -avz --progress -e ssh /path/to/local/folder/ sshuser@server.com:/path/to/remote/folder

SCP

scp pathandfiletotransfer remoteuser@servername:pathtosaveonserver

Get Server Load/Stats (Ubuntu)

landscape-sysinfo

Sample

System load:  0.0               Processes:           81
  Usage of /:   69.0% of 1.97TB   Users logged in:     1
  Memory usage: 39%               IP address for eth0: XXX.XXX.XXX.XXX
  Swap usage:   0%

  Graph this data and manage this system at https://landscape.canonical.com/

MySQL Server

Export MySQL Database

mysqldump -u username -p database_name > dump.sql

Import MySQL Database

mysql -u username -p -h servername database-name < data.sql

Login MySQL Database

mysql -uusername -p

Users

Add Users

sudo useradd -d /home/testuser -m testuser

Change User Password

sudo passwd testuser

Add User To Group

sudo usermod -a -G group username

Remove User From Group

sudo deluser username group

Terminal and Language Config

Bash Autocomplete Not Working

apt-get install bash-completion

Set Bash as the Default Shell

chsh

Set Timezone

dpkg-reconfigure tzdata

Basic Commandline For Managing Linux LAMPP Server

More command line reference… click here

%d bloggers like this: