View: 3848|Reply: 2
|
Linux Shortcuts and Commands
[Copy link]
|
|
by Stan and Peter Klimas
This is a practical selection of the commands we use most often. Press<Tab>to see the listing of all available command (on your PATH). On my small home system, it says there are 2595 executables on my PATH. Many of these "commands" can be accessed from your favourite GUI front-end (probably KDE or Gnome) by clicking on the right menu or button. They can all be run from the command line. Programs that require GUI have to be run from a terminal opened under a GUI.
Legend:
<> = single special or function key on the keyboard. For example<Ctrl> indicates the "control" key.
italic = name of the file or variable you probably want to substitute with your own.
fixed width = in-line Linux commands and filenames.
Notes for the UNIX Clueless:
1. LINUX IS CASE-SENSITIVE. For example: Netscape, NETSCAPE and nEtscape are three different commands. Also my_filE, my_file, and my_FILE are three different files. Your user login name and password are also case sensitive.(This goes with the tradition of UNIX and the "c" programming language being case sensitive.)
2. Filenames can be up to 256 characters long and can contain letters,numbers, "." (dot), "_" (underscore), "-" (dash), plus some other not recommended characters.
3. Files with names starting with "." are normally not shown by the ls(list) or dir commands. Think of these files as "hidden". Use ls -a (list with the option "all") to see these files.
4. "/" is an equivalent to DOS "\" (root directory, meaning the parent of all other directories).
5. Under Linux, all directories appear under a single directory tree(there are no DOS-style drive letters).
6. In a configuration file, a line starting with # is a comment.
7.1 Linux essential shortcuts and sanity commands<Ctrl><Alt><F1>
Switch to the first text terminal. Under Linux you can have several(6 in standard setup) terminals opened at the same time.
<Ctrl><Alt><Fn> (n=1..6)
Switch to the next text terminal.
tty
Print the name of the terminal in which you are typing this command.
<Ctrl><Alt><F7>
Switch to the first GUI terminal (if X-windows is running on this terminal).
<Ctrl><Alt><Fn> (n=7..12)
Switch to the nth GUI terminal (if a GUI terminal is running on screen-1). On default, nothing is running on terminals
8 to 12, but you can run another server there.
<Tab>
(In a text terminal) Auto complete the command if there is only one option, or else show all the available options.
THIS SHORTCUT IS GREAT! It even works at LILO prompt!
<ArrowUp>
Scroll and edit the command history. Press <Enter> to execute.
<Shift>< PgUp>
Scroll terminal output up. Work also at the login prompt, so you can scroll through your bootup messages.
<Shift>< PgDown>
Scroll terminal output down.
<Ctrl><Alt><+>
(in X-windows) Change to the next X-server resolution (if you set up the X-server to more than one resolution). For multiple resolutions on my standard SVGA card/monitor, I have the following line in the file/etc/X11/XF86Config(the first resolution starts on default, the largest determines the size of the "virtual screen"):
Modes "1024x768" "800x600" "640x480" "512x384" "480x300" "400x300""1152x864"
<Ctrl><Alt><->
(in X-windows) Change to the previous X-server resolution.
<Ctrl><Alt><BkSpc>
(in X-windows) Kill the current X-windows server. Use if the X-windows server crushes and cannot be exited normally.
<Ctrl><Alt><Del>
Shut down the system and reboot. This is the normal shutdown command for a user at the text-mode console. Don't just press the "reset" button for shutdown!
<Ctrl>c
Kill the current process (mostly in the text mode for small applications).
<Ctrl>d
Log out from the current terminal. See also the next command.
<Ctrl>d
Send [End-of-File] to the current process. Don't press it twice else you also log out (see the previous command).
<Ctrl>s
Stop the transfer to the terminal.
<Ctrl>q
Resume the transfer to the terminal. Try if your terminal mysteriously stops responding.
<Ctrl>z
Send the current process to the background.
exit
Logout. I can also use logout for the same effect. (Ifyou have started a second shell, e.g., using bash the second shell will be exited and you will be back in the first shell, not logged out.)
reset
Restore a screwed-up terminal (a terminal showing funny characters)to default setting. Use if you tried to "cat" a binary file. You may not be able to see the command as you type it.
<MiddleMouseButton>
Paste the text which is currently highlighted somewhere else. This is the normal "copy-paste" operation in Linux. (It doesn't work with Netscape and WordPerfect which use the MS Windows-style "copy-paste". It does work in the text terminal if you enabled "gpm" service using "setup".)Best used with a Linux-ready 3-button mouse (Logitech or similar) or else set "3-mouse button emulation").
~
(tilde) My home directory (normally the directory /home/my_login_name).For example, the command cd ~/my_dir will change my working directory to the subdirectory "my_dir" under my home directory. Typing just "cd" alone is an equivalent of the command "cd ~".
.
(dot) Current directory. For example, ./my_program will attempt to execute the file "my_program" located in your current working directory.
..
(two dots) Directory parent to the current one. For example, the command cd.. will change my current working directory one one level up.
7.2 Common Linux commands--system info
pwd
Print working directory, i.e., display the name of my current directory on the screen.hostname
Print the name of the local host (the machine on which you are working).Use netconf (as root) to change the name of the machine.
whoami
Print my login name.
id username
Print user id (uid) and his/her group id (gid), effective id (if different than the real id) and the supplementary groups.
date
Print or change the operating system date and time. E.g., I could change the date and time to 2000-12-31 23:57 using this command:
date 123123572000
To set the hardware (BIOS) clock from the system (Linux) clock, use the command (as root) setclock
time
Determine the amount of time that it takes for a process to complete+ other info. Don't confuse it with the date command. E.g. I can find out how long it takes to display a directory content using:
time ls
who
Determine the users logged on the machine.
rwho -a
(=remote who) Determine all users logged on your network. The rwho service must be enabled for this command to run. If it isn't, run setup as root to enable "rwho".
finger user_name
System info about a user. Try: finger root
last
Show listing of users last logged-in on your system.
history | more
Show the last (1000 or so) commands executed from the command line on the current account. The "| more" causes the display to stop after each screenful.
uptime
Show the amount of time since the last reboot.
ps
(=print status) List the processes currently run by the current user.
ps axu | more
List all the processes currently running, even those without the controlling terminal, together with the name of the user that owns each process.
top
Keep listing the currently running processes, sorted by cpu usage (top users first). In KDE, you can get GUI-based Ktop from "K"menu under "System"-"TaskManager" (or by executing "ktop" in an X-terminal).
uname -a
(= Unix name with option "all") Info on your (local) server. I can also use guname (in X-window terminal) to display the info more nicely.
free
Memory info (in kilobytes).
df -h
(=disk free) Print disk info about all the filesystems (in human-readable form)
du / -bh | more
(=disk usage) Print detailed disk usage for each sub directory starting at the "/" (root) directory (in human legible form).
cat /proc/cpuinfo
Cpu info--it show the content of the file cpuinfo. Note that the files in the /proc directory are not real files--they are hooks to look at information available to the kernel.
cat /proc/interrupts
List the interrupts in use.
cat /proc/version
Linux version and other info
cat /proc/filesystems
Show the types of filesystems currently in use.
cat /etc/printcap
Show the setup of printers.
lsmod
(As root. Use /sbin/lsmod to execute this command when you are a non-root user.) Show the kernel modules currently loaded.
set|more
Show the current user environment.
echo $PATH
Show the content of the environment variable "PATH". This command can be used to show other environment variables as well. Use "set" to see the full environment.
dmesg | less
Print kernel messages (the content of the so-called kernel ring buffer).Press "q" to quit "less". Use less /var/log/dmesg to see what "dmesg" dumped into this file right after the last system bootup.
[ Last edited by iek at 24-12-2008 09:35 AM ] |
Rate
-
1
View Rating Log
-
|
|
|
|
|
|
|
7.3 Basic operations
any_command --help |more
Display a brief help on a command (works with most commands). "--help"works similar to DOS "/h" switch. The "more" pipe is needed if the outputis longer than one screen.
man topic
Display the contents of the system manual pages (help) on the topic.Try man man first. Press "q" to quit the viewer. The command infotopicworks similar and may contain more up-to-date information. Manual pagescan be hard to read. Try any_command --help for short,easy to digest help on a command. If more info needed, have a look to thedirectory /usr/doc. To display manual page from a specific section,I may use something like in this example: man 3 exit (thisdisplays an info on the command exit from section 3 of the manualpages).
apropos topic
Give me the list of the commands that have something to to do withmy topic.
help command
Display brief info on a bash (shell) build-in command.
ls
List the content of the current directory. Under Linux, the command"dir" is an alias to ls. Many users have "ls" to be an alias to "ls --color".
ls -al |more
List the content of the current directory, all files (also those startingwith a dot), and in a long form. Pipe the output through the "more" command,so that the display pauses after each screenful.
cd directory
Change directory. Using "cd" without the directory name will take youto your home directory. "cd -" will take you to your previous directoryand is a convenient way to toggle between two directories. "cd .." willtake you one directory up.
cp source destination
Copy files. E.g., cp /home/stan/existing_file_name . will copy a file to my current working directory. Use the "-r" option (forrecursive) to copy the contents of whole directories, e.g. , cp -rmy_existing/dir/ ~ will copy a subdirectory under my currentworking directory to my home directory.
mcopy source destination
Copy a file from/to a DOS filesystem (no mounting necessary). E.g.,mcopya:\autoexec.bat ~/junk . See man mtools for related commands:mdir, mcd, mren, mmove, mdel, mmd, mrd, mformat ....
mv source destination
Move or rename files. The same command is used for moving and renamingfiles and directories.
ln source destination
Create a hard link called destination to the file called source.The link appears as a copy of the original files, but in reality only onecopy of the file is kept, just two (or more) directory entries point toit. Any changes the file are automatically visible throughout. When onedirectory entry is removed, the other(s) stay(s) intact. The limitationof the hard links are: the files have to be on the same filesystem, hardlinks to directories or special files are impossible.
ln -s source destination
Create a symbolic (soft) link called "destination" to the file called"source". The symbolic link just specifies a path where to look for thefile. In contradistinction to hard links, the source and destination don'tnot have to tbe on the same filesystem. In comparison to hard links, thedrawback of symbolic links are: if the original file is removed, the linkis "broken", symbolic links can also create circular references (like circularreferences in spreadsheets or databases, e.g., "a" points to "b" and "b"points back to "a").
rm files
Remove (delete) files. You must own the file in order to be able toremove it. On many systems, you will be asked or confirmation of deleation,if you don't want this, use the "-f" (=force) option, e.g., rm -f * will remove all files in my current working directory, no questions asked.
mkdir directory
Make a new directory.
rmdir directory
Remove an empty directory.
rm -r files
(recursive remove) Remove files, directories, and their subdirectories.Careful with this command as root--you can easily remove all files on thesystem with such a command executed on the top of your directory tree,and there is no undelete in Linux (yet). But if you really wanted to doit (reconsider), here is how (as root):rm -rf /*
cat filename | more
View the content of a text file called "filename", one page a time.The "|" is the "pipe" symbol (on many American keyboards it shares thekey with "\") The pipe makes the output stop after each screenful. Forlong files, it is sometimes convenient to use the commands head and tailthat display just the beginning and the end of the file. If you happenedto use "cat" a binary file and your terminal displays funny charactersafterwards, you can restore it with the command "reset".
less filename
Scroll through a content of a text file. Press q when done. "Less"is roughly equivalent to "more" , the command you know from DOS, althoughvery often "less" is more convenient than "more".
pico filename
Edit a text file using the simple and standard text editor called pico.
pico -w filename
Edit a text file, while disabling the long line wrap. Handy for editingconfiguration files, e.g. /etc/fstab.
find / -name "filename"
Find the file called "filename" on your filesystem starting the searchfrom the root directory "/". The "filename" may contain wildcards (*,?).
locate filename
Find the file name of which contains the string "filename". Easierand faster than the previous command but depends on a database that normallyrebuilds at night.
./program_name
Run an executable in the current directory, which is not on your PATH.
touch filename
Change the date/time stamp of the file filename tothe current time. Create an empty file if the file does not exist.
xinit
Start a barebone X-windows server (without a windows manager).
startx
Start an X-windows server and the default windows manager. Works liketyping "win" under DOS with Win3.1
startx -- :1
Start another X-windows session on the display 1 (the default is openedon display 0). You can have several GUI terminals running concurrently.Switch between them using <Ctrl><Alt><F7>, <Ctrl><Alt><F8>,etc.
xterm
(in X terminal) Run a simple X-windows terminal. Typing exitwill close it. There are other, more advanced "virtual" terminalsfor X-windows. I like the popular ones: konsole and kvt(both come with kde) and gnome-terminal (comes with gnome). If you need something really fancy-looking, try Eterm.
xboing
(in X terminal). Very nice, old-fashioned game. Many small games/programsare probably installed on your system. I also like xboard (chess).
shutdown -h now
(as root) Shut down the system to a halt. Mostly used for a remoteshutdown. Use <Ctrl><Alt><Del> for a shutdown at the console (whichcan be done by any user).
halt
reboot
(as root, two commands) Halt or reboot the machine. Used for remoteshutdown, simpler to type than the previous command.
File (de)compressiontar
-zxvf filename.tar.gz
(=tape archiver) Untar a tarred and compressed tarball (*.tar.gz or*.tgz) that you downloaded from the Internet.tar -xvf filename.tar
Untar a tarred but uncompressed tarball (*.tar).
gunzipfilename.gz
Decompress a zipped file (*.gz" or *.z). Use gzip (also zipor compress) if you wanted to compress files to this file format.
bunzip2filename.bz2
(=big unzip) Decompress a file (*.bz2) zipped with bzip2 compressionutility. Used for big files.
unzipfilename.zip
Decompress a file (*.zip) zipped with a compression utility compatiblewith PKZIP for DOS.
unarj e filename.arj
Extract the content of an *.arj archive.
uudecode -o outputfile filename
Decode a file encoded with uuencode. uu-encoded filesare typically used for transfer of non-text files in e-mail (uuencode transformsany file into an ASCII file).
[ Last edited by iek at 20-11-2008 03:32 AM ] |
|
|
|
|
|
|
|
ni byk command unix/linux
bagus utk newbie |
|
|
|
|
|
|
| |
|