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/

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

Change Default Shell

If you want to change the shell of already existing users you have to edit the /etc/passwd file (please make sure to back have a backup of it).

Here is a description of the columns

login name
optional encrypted password
numerical user ID
numerical group ID
user name or comment field
user home directory
optional user command interpreter
In that order separated by colons (:) like this.

root:x:0:0:root:/root:/bin/bash

Set Timezone

dpkg-reconfigure tzdata

Basic Commandline For Managing Linux LAMPP Server

More command line reference… click here