Category: Basic commands

Basic Linux Commands

By peter, September 13, 2009

Log on, off, shutdown and reboot (command in italics)


exit
log off

shutdown -h now message
Other options -r, -c. Use time instead for “now”, eg 20 for 20 mins. Can leave out message.

reboot
Reboot

intit 0
Shutdown

init 6
Reboot

Basic commands (command in italics)
Here are some of the basic commands that will help you to navigate while working in the “shell”.
Please be aware that Linux is very case sensitive

pwd
Print working directory

ls
List files and folders

cd
Change directory (as with Dos)

cd ..
Back

cd ~
Change to home directory

cd /
Change to root directory

history
All resent commands used


TIP:: You can use the “tab” key to complete a command.
With SuSE you can type the first few letters of a command and then use the “page up” and “page down” key to give you the last command typed starting with those letters. This is nice because it will give you the whole syntax.
With most other distros you can use “Ctrl” + “r” to search for commands used.

The following are some of the basic “shell” commands you might be using:

less
Allows you to see the content of a file page by page. (even “zipped” files) eg “less /etc/hosts” you can also “pipe” an output to “less” for example, see the difference when you type “ls” on the “etc” directory and when you type “ls | less” , press “enter” to see more and type”q” to escape. The “|” or “pipe” is the thing on your keyboard that looks like two “dashes” above one another.

more
Similar to “less”

cd
Change directory eg “cd /home”

cd ..
Go back a directory

vi
Open the vi Text editor Eg “vi /etc/samba/smb.conf”

ls
List content (dir also works)

ls -al
List content and shows permissions

pwd
Shows you the working directory where you are currently working from

ifconfig
Shows the IP configuration (like �ipconfig� in Microsoft)

netstat
Displays the status of all open sockets

traceroute
Displays the route to a host (like “tracert” in Microsoft)

df
Shows you disk usage and where partitions are mounted

du
Shows disk usage by folders and files

free
Shows free memory

uptime
Tells you how long the system has been up

cp text.txt /folder/test.txt
Copy a text doc You can use the�*� as a wild card as you can in DOS

rm text.txt
Delete a text doc. To remove entire directories along with the files you need to use the “rm” command with the “-R” switch. To force you can use the “-f”. To require conformation when deleting use “-i”, although some distros have “rm” as an alias for “rm -i”

rmdir
(Delete an empty directory)

mv text.txt /foldername/backup.txt
(Moves a text doc)

ifconfig
Shows the IP configuration (like “ipconfig” in Microsoft)

netstat
Displays the status of all open sockets

traceroute
Displays the route to a host (like �tracert� in Microsoft)

df
Shows you disk usage and where partitions are mounted

du
Shows disk usage by folders and files

free
Shows free memory

uptime
Tells you how long the system has been up

vmstat 1
Shows activity memory

top
Shows list of processes ( you can change the sorting columns by typing “F” then “n” (or what ever other letter representing a column. You can choose from a list)

touch

Creates a file

cat
Concatenates a file or files

ping
Same as Microsoft pinc

mail -v -s “Backup done” -a /scripts/text.txt < /scripts/bkp.txt peterh@lw.co.za

to e-mail from the shell. Great for including in scripts.

OfficeFolders theme by Themocracy