Linux Shell Commands
Basic commands
This page is a just a collection of Linux shell commands for my own personal reference while I learn (it saves me reaching for my big book of Linux and flipping to the same old pages). A more comprehensive command reference is here.
Self-explanatory commands:
cd <dir>
mkdir <dir>
cp <file> <destination>
mv <file> <destination>
rm <file>
Check current directory:
pwd
List a directory (detailed list, include hidden files):
ls -la <target dir>
Create empty files:
touch <file1> <file2> <file3>
Change permissions (rwx------) of a file or directory:
chmod 700 <file or dir>
Processes and their runlevels (Samba as an example - note smb is the service, smbd and nmbd are the daemons):
service smb start
service smb restart
service smb stop
chkconfig -level 35 smb on
chkconfig -list smb
List running processes (piped to 'less' for paging through long list):
ps aux | less
Show environment variables (e.g. user's path):
echo $PATH
Where a command comes from (which dir in the path is being used):
type <command>
Getting help:
help | less
<command> --help
man <command>
info
Text Editor: vi
Starting in command mode, Esc always places you back in command mode...
- a - add (input text to the right of the cursor)
- i - insert (input text to the left of the cursor)
- w - move cursor to beginning of next word
- b - move cursor to beginning of previous word
- 0 (zero) - home
- $ - end
- H - move cursor to upper left of screen
- M - move cursor to middle left of screen
- L - move cursor to lower left of screen
- x - delete character under cursor
- X - delte character before cursor
- dw - delete from current character to end of word
- d$ - delete from current character to end of line
- d0 - delete from previous character to beginning of line
- ZZ - save changes and exit
- :w - save changes (write)
- :wq - save changes and exit (write, quit)
- :q - quit (only if no unsaved changes)
- :q! - quit without saving
- u - undo
- Ctrl+R - redo
- Ctrl+G - display file name, current line, total lines, % and current column (get your bearings back!)
- Ctrl+F - page ahead (one page, forward)
- Ctrl+B - page back (one page, back)
- Ctrl+D - page ahead (half page, down)
- Ctrl+U - page back (half page, up)
- G - go to last line
- 1G - go to first line (any number for any given line)
Searching for text:
- /hello - searches forward for the word "hello"
- ?goodbye - searches backward for the word "goodbye"
- /[Pp]rint - searches forward for either "Print" or "print"
More Advanced Stuff
Watching a log file: (from the NSLU2 DNS setup tutorial) "...At this point you could start the bind server by issuing a 'start' argument to the initialisation script that the ipkg installation routine installed. But I advise you to open another ssh session to the server and watch the syslog file in realtime as you start the bind server in the original ssh window. Once you've opened the second ssh session, issue the command:
tail -f /var/log/messages
to see incoming messages as you start the bind server."
Scanning ports to check availability: (from the NSLU2 DNS setup tutorial) "...If the sever looks as though it started correctly, you can test if it is visible and working to your LAN clients. I test that it is visible by using nmap on a separate Linux box, with the command:"
nmap -sS <DNS_server_IP>
