General Linux Commands

Just a small collection of commands that I will add to as I find them.....

Getting around + File commands

cd - changes to your home directory
rm -rf - removes a directory without prompting. ==USE WITH CAUTION!!!!!!==
cd /home/someguy - changes directory to /home/someguy
cd .. - moves up one directory
pwd - shows the current directory your in
mkdir somedir - creates a new directory call somedir
ls - lists the directory and files. ls -al shows hidden files and shows the permissions on the listed files too
cp one two - copies file one to file two
mv one two - renames one to two and obviosuly moves it if another directory is specified.
touch somefile - creates a file called somefile
vi somefile - opens somefile with the vi editor
cat somefile - outputs the contents of somefile into the shell
tail somefile - outputs the last 10 lines of somefile by default -n changes this where n is the number of lines required. tail -f somefile I have found very useful too, it shows the contents of a file as it grows. Handy for log files and seeing whats going on.
ln -s file linkedfile - creates a symbolic link from file to linkedfile. E.g when installing the flash plugin for FF.
wget http://somehost/somefile - Will download somefile to the local machine. http is only used as an example!
rm -r dir - Removes a directory while prompting
rm somefile - removes somefile while prompting

SSH


scp somefile user@somehost:/somedir/dir - will copy somefile from the local machine to somehost using user and to the location specified. Prompts for password if required.

ssh -p $ user@somehost - connect to somehost on port '$' as user

ssh-copy-id user@somehost - adds the local systems key for user on somehost so you can login without password prompting in future.  The command doesnt seem to allow for the use of a non default port(22) as far as I can see :( It may be required to run ssh-keygen before this command.

ssh-keygen - generates a public/private key pair for ssh

File Permissions

chmod OCTAL 'file or directory' - Changes the permissions on the file or directory with the supplied OCTAL. The permissions are split into three categories owner, group and world. The three octal digits are ordered like that ie digit one is the owners permissions, digit two the group and digit three worlds. The permissions you want to set can be summarized as a single digit by adding the sum of the values shown below.

  • READ       -  4 (r)
  • WRITE      - 2 (w)
  • EXECUTE - 1 (x)
>chmod -R 666 somefolder/ - will change the permissions of somefolder, every sub directory and file in them to 666. chown -R would change the owner of a directory and sub directories/files E.g chmod 777 somefile - Gives read, write and execute for everyone. chmod 630 somefile - Gives read & write permissions to owner, write and execute to group and no permissions at all to world. chown root:staff 'file or directory' - Changes the owner of the file or directory to root and its group to staff. The group part of this command isnt mandatory. Both chmod and chown can use the -R option to apply changes to subfolers if required

Compression


gzip somefile - Compress somefile with gzip and rename it to somefile.gz

tar czf somefile.tar.gz files - Create a tar called somefile.tar.gz containing the files named and use Gzip compression

tar cjf somefile.tar.bz2 files - Create a tar called somefile.tar.bz2 containing the files named and use Bzip2

Decompression


tar cjf somefile.tar.bz2 - Extract a tar called somefile.tar.bz2 with Bzip2

tar xf somefile.tar - Extract the somefile.tar

gzip -d somefile.gz - Extract files from somefile.gz

unzip somefile.zip - Extract files from somefile.zip

Network stuff


whois somedomain - Gets the whois info and displays it to the shell.

dig somedomain - Gets the dns info and displays it to the shell. -x can be used to reverse lookups

netstat -a - lists all listening/active ports.

netstat -a | grep tftp - will output all the ports if any tftp is using. Usefull to see if a program is running etc

traceroute somehost - Performs a trace route.....

Processes etc


yum install somepackage - Gets somepackage and installs is

yum clean all - Cleans yum up if you're having problems has been useful after yum crashed.

ps -A - Shows all processes currently running

top - shows a task manager type output.

free - shows memory and swap usage

date - displays the date and time

cal - shows this months clander

uptime - shows uptime....

man somecommand - shows the manual for somecommand

df - shows disk usage

du - shows directory usage

finger someuser - Shows info about someuser

kill pid - kills the selected process -9 might be required sometimes

killall someprocess - kills all processes name someprocess

history - shows a list of your past commands

service someservice status - will make someservice into the staus selected eg. service httpd start would start apache. if you enter the command without selecting a status it will list the available ones for that service.

chkconfig someservice status - makes someservice start (or not) on boot e.g chkconfig postfix on would start postfix with every boot.