Thursday, 25 July 2013

Useful Unix Commands

This is a list of basic linux commands which I find useful.  If you have any suggestions please let me know in the comments.


apachectl restart : restart your webserver or /etc/init.d/httpd restart

apachectl -e debug : error log to screen

apt-get install <package name>: download and install a package (library/programme/application)

cat <file> : shows the contents of the file on the command line

cat /etc/*release: shows details of the OS you're running

cp -r * ../copyfolder: copies content of current folder, including any directories, to 'copyfolder' in the same parent.

echo $PATH : displays the path environmental variable

export PATH=$PATH:/new/pathitem: adds a new item to path, useful if you want to use a buried command without having to type its path everytime

find <path> -name <filename> : finds filename with wildcards in path, / to search everywhere

find <path1> <path2> <path n> -name <filename> : finds filename in multiple paths, . is current directory

find . -exec touch {} \; : touch changes the date/time of a file to now, the rest does it to all files in the directory tree from the current folder down.

git clone <path to .git file>: copies the content of a git repository to your pwd, (apt-get install git)

grep -r <text> .: search for files containing <text> in current directory and (with -r) its child folders

ls : list contents of a directory
ls -a : lists all contents of a directory including hidden items
ls -l : lists all contents of a directory including attributes of a directory e.g. permission, date
ls -al : lists all contents of a directory including hidden items and attributes

man <command> : displays manual page for the <command>

nano : a text editor.  ctrl-g shows a list of keystroke shortcuts

passwd: change the current user's password
passwd <username>: change a user's password

python: starts the python shell if it's installed
python <filename.py>: executes a python source code file

rm -R <name> : removes a non-empty directory

shutdown -h now : shutdown the computer immediately

sips : scriptable image processing system, sips --help, sips -Z 680 *.jpg, sips -r 90 *.png
ssh <username>@your.ip.add.ress : secure shell connection to a remote computer

su root : change to root user
sudo <command> : execute command as superuser

<tab key> : auto-completes a command/filename, press it again to list the possibilities

tail -f var/log/system.log : shows anything logged by the system.  There are many logs in /var/log, you can tail any file with this command to show any changes

tar -xzvf  <filename with extension>.tar.gz : Unpacks a tar ball.

No comments:

Post a Comment