|
Linux/UNIX Commands & Apt-get Commands
Linux Tutorials: Linux.org | http://www.ctssn.com | ||
A note on hardening Linux: In 2004, the W32.Blaster.Worm and other similar worms were spread by simply surfing on the Internet. Windows is currently more vulnerable to viruses and worms because malware was written to attack the Windows operating system, but as Linux grows in popularity, expect similar problems. "Trojan Horse attacks GNU Project", read the article here. | ||
| ls | Lists files. The equivalent of "dir" in DOS. Common switches are -al which will list all files with a long description, including their permissions, size, and datestamp. You can also type in ls -al followed by a specific filename to learn information about that specific file. This is helpful if you have many files within a directory and you only want information on one of them. You can even use wildcards. For example, ls *.html shows only files with extension .html | |
| uname -a,-s,-r | Show info about the current machine, kernel and operating system. | |
| pwd | Print Working Directory, also Present Working Directory: Wonder which directory you're currently in? pwd reveals the full path. | |
| clear | clear the screen | |
| touch | touch <filename>. If filename doesn't exist it gets created (0 byte). If filename already exists, touch alters its timestamp to the current time. Please note, in UNIX we can not easily name files with spaces in them, so words should use underscores or a capital letter to separate them. For example, touch my file will not work. You must write either touch myFile or touch my_file . This applies to creating directories as well. Other ways to create a new file: cat > newfile and ls > newfile will also create a new file. See redirecting output symbol > below... | |
| mkdir | makes a directory. | |
| rmdir | removes an empty directory. If it is not empty, you can use rm -r <dir name>. | |
| rm | Removes files. You can use it with wildcards too. For example rm -f *.html will remove all html files in the directory. You can use rm to remove a directory with an -r or -rf switch. However, this is not the ideal way to remove directories. | |
| cp | cp originalFile newFile Creates a copy of the first file having the name of the second. If the paths are not specificied, then cp assumes you mean the current working directory. You can also copy a file to another location. For example, cp OriginalFile /home/someDirectory/newFile will copy a file from the current directory to another directory with "NewFile" as it's name. If no name is specified, and you are copying the file to another directory, then the original filename will be used. | |
| file | file tests each argument and tries to classify File Type using three tests performed in this order: filesystem, magic number, and language. The first test that succeeds causes the file type to be printed: text, executable, data and others. In this example, 'x-window-manager' is the argument: Using Debian/Linux shell, from /usr/bin$ file x-window-manager x-window-manager: symbolic link to /etc/alternatives/x-window-manager | |
| ln | Create a link to the specified target with optional link_name. If link_name is omitted, a link with the same base name as the target is created in the current directory. ln -s creates a symbolic link which allows for later removal of the link without removing the original file. Use the rm command: rm <filename> | |
| whatis | whatis searches a set of database files containing short descriptions of system commands for keywords and display the result on the standard output (stdout). Only complete word matches are displayed. | |
| whereis | whereis locates source/binary and manuals sections for specified files. The supplied names are first stripped of leading pathname components and any (single) trailing extension of the form .ext, for example, .c. Prefixes of s. resulting from use of source code control are also dealt with. whereis then attempts to locate the desired program in a list of standard Linux places. | |
| find | find will locate files from a shell command prompt, e.g., find / -name 'FAQ' for a list of FAQ file locations. Enclose the filename in single quotes with the find command. | |
| who | who is using the Linux server at this time. who -a for time of last system boot, active processes spawned by init, dead processes, current run level and lists users logged in. Try who am i and/or who mom likes. Also try ls -last for recent login info on your server. | |
| which | which takes one or more arguments. For each of its arguments it prints to stdout the full path of the executables that would have been executed when this argument had been entered at the shell prompt. It does this by searching for an executable or script in the directories listed in the environment variable PATH using the same algorithm as bash. | |
| echo |
| |
| wc | The wc command will give you the number of lines, words and letters (characters) in a file and in that order. Example from /var/www directory, type: wc -w index.html will display the word count of index.html. | |
| cal | Cal displays a simple calendar. If arguments are not specified, the current month is displayed. cal -y displays the current year and cal 08 2003 displays the month of August, 2003. If you add the option cal -m, the week will start on Monday, as it is preferred in many countries. Debian: ncal to print a calendar starting on Monday. | |
| date |
| |
| exit | You can get out of a terminal with the exit command. If you're working in text mode, typing exit will prompt you to login again. If you want to work as another user, use logout instead. If you're in x-windows, exit will close the X-Terminal you're working with. | |
| last | The command last will show you the people who have logged into the computer today and the terminals they are/were using. Last searches back through the file /var/log/wtmp or the file designated by the -f flag and displays a list of all users logged in and out since that file was created. Also try this command: ls -last | |
| mount | The mount command serves to attach the file system found on some device to the big file tree. Conversely, the umount command will detach it again. All files accessible in a Unix system are arranged in one big tree, the file hierarchy is rooted at /. These files can be spread out over several devices. The standard form of the mount command, is mount -t type device dir You can also use the mount command to copy to and from other devices. If you would like to get some files from a CD-ROM, the standard command to do this is:
More from Linux.org: http://www.linux.org/lessons/beginner/l13/lesson13d.html | |
| umount | The umount command detaches the file system(s) mentioned in the file hierarchy. A file system is specified either by giving the directory where it has been mounted, or by giving the special device on which it lives. A file system cannot be unmounted when it is 'busy' - for example, when there are open files on it, or when some process has its working directory there, or when a swap file on it is in use. | |
| cron | cron is a program on Linux systems that allows programs to be run automatically at certain times and under certain conditions. Cron searches /var/spool/cron for crontab files which are named after accounts in /etc/passwd; crontabs found are loaded into memory. | |
|
Linux File system
| / | (Called root), this is equivalent to C:\ in the DOS/Windows world. You cannot run a Linux system without the root partition. All other partitions are a subset of the root partition. |
| swap | Unless you have massive amounts of memory, you are going to need some swap space. In Windows, you have Win386.swp; here, it's a separate drive partition. |
| /boot | This contains the necessary stuff to start the machine, including the base kernel. This partition is optional, but usually present. You will not need to mess around in here if you have a running system. |
| /usr | This is the directory where global executables are stored. It can be read-only, if you want. Generally speaking, most software is installed here by default. |
| /dev | This is the directory where all of your devices are. There are a few useful examples for you to know. /dev/hda is the first ide hard drive. /dev/hdb is the second. /dev/sda would be the first SCSI drive... |
| /etc | This is where most configuration files are stored. You will spend a lot of time in here if you are an administrator. Most files require "root" access to change. |
| /var | Many of the system log files are here, as well as spools (mail, printer...) |
| /bin | This directory is the home of binary executables. These include the common commands like ls, cat, gzip and tar. |
| cat | Concatenate files and print on standard output. Works like the DOS "TYPE" command. Simply put, "cat" can be used to read the contents of a file, combine files or to create a new file: cat > newfilename. | |||||||||
| chmod | Change the permissions on a file or directory. 1 = execute 2 = write 4 = read, now add 1 plus 2 plus 4 = 7, thus chmod 700 filename gives full permission to the file Owner. chmod 755 filename gives Owner full permission, Group has read and execute permissions and Everyone else has read and execute permissions. more... chmod explained. (Table below from Linux.org Tutorial.) | |||||||||
| chown | The command chown is used for changing the ownership rights of a file (hence the name 'chown' - change owner). It does not change the read, write and execution permissions. more... from Linux.org | |||||||||
| chgrp | chgrp is a standard UNIX/Linux command that allows you to change the group of a file/directory. To change the owner of a file/directory, become root by either logging in directly as the user root or use the su command as a normal user. Then you would type "chgrp newGroup filename" where newGroup is the group-name you want to change group ownership to and filename is the name of the file or directory. | |||||||||
| grep | Find line matching a certain pattern. Very powerful search tool. | |||||||||
| less | Filter for viewing files and directories. Works the same as the "more" command, but lets you scroll backwards. It is a little bulkier than more. | |||||||||
| more | Filter for viewing files and directories a screen at a time. | |||||||||
| mv | Move or rename a file | |||||||||
| > | Redirect - A cool feature of Linux is that you can easily send the info that normally gets printed on the screen into a text file instead. This is called redirecting output. For example, ls > newFile, will list all files in a directory and write them to a file called "newFile". If "newFile" already exists, the contents will be over-written, otherwise a new file will be created. This very useful feature can be used with many Linux commands. Does what the "pipe" command does with fewer keystrokes. Try this command to save a copy of a traceroute: traceroute yahoo.com > /home/username/traceroute Traceroute is now available with Debian: apt-get install traceroute | |||||||||
| >> | Append the output of a program to a file. If the file does not already exist, it will be created. If it does already exist, the output will be written to the end of the file. Example: traceroute localtech.us >> /home/username/traceroute | |||||||||
| | | Called the pipe command, it is used to redirect the output of a command to another command. | |||||||||
| /var/log/messages | Command: tail -20 /var/log/messages (-20 is the variable, specify your own.) Debian start-up information: /var/log Command: cat dmesg |
Commands Sources: http://www.ctssn.com/, http://www.linux.org/ and various Internet Web Sites. I want to try Linux/UNIX. Now What? Install Debian, then using Apt-get and/or Synaptic, choose from over 8700 additional packages including an Apache web server. Use this link to get started: http://localtech.us/notes.htm. "Debian was easy to install, is extremely fast and the Apache Server really works". |
Linux System Administration
| su | Switch user. If you are logged in as a user, you can type in "su username" and you will be given a log in prompt for username. You will have to provide a password to actually log in. Typing "su" without a username is equivalent to "su root" and you will be prompted for the root password. |
| useradd Debian is adduser | This program adds a user to the system. For example, you can type useradd foobar to add the user foobar to the system. If you type useradd -m foobar, foobar will be added to the system and a home directory will be created. If you add a user to the system, you must add a password before they can use the account. |
| userdel Debian is deluser | This command is used to delete a user from the system. Only root can run this program by typing userdel username . If you want to delete the user's home directory at the same type, use an -r switch. userdel -r username |
| passwd | This command changes the password on an account. In order to change (or add) foobar's password, root would type passwd foobar . If a user runs the command, passwd, he or she will be prompted for a new passwd for their own account. |
df df -h | A command that you're going to use a lot if you're pressed for hard disk space. Once again, there are many programs that run graphically that will inform you of the space available on your Linux partition. But this is a very good, quick, non-graphic way to keep track of your hard disk space. |
| free | Displays the total amount of free and used physical and swap memory in the system, as well as the shared memory and buffers used by the kernel. |
| du | Summarize disk usage of each FILE, recursively for directories. -a, --all write counts for all files, not just directories |
| top | Here you will see what processes are running. Top is a good command to use when you want to see what your system's doing. Top is designed to show you how your CPU is being used. It will give you a pretty complete list of everything that's going on in your computer. Command: top -s (secure mode) is best. |
| ps ps aux | Will give you a list of the processes running on your system. Just typing ps will give you the processes you're running as a user. ps au to see other users processes. ps aux Lists the applications that are now running with its PID (Process Identifier). ps aux | more Pauses between screens. Very useful to get information to kill a running process. Note: ps gives a snapshot of the current processes. If you want a repetitive update of this status, use top. |
| kill | The command kill sends the specified signal to the specified process or process group. If no signal is specified, the TERM signal is sent. The TERM signal will kill processes which do not catch this signal. For other processes, it may be necessary to use the KILL (9) signal, since this signal cannot be caught. |
| make a floppy |
|
| lpr, lpq, lpd Print, print spooler & printer | Printer Tutorial for Linux: |
| Sound How-To | The Sound Tutorial from Linux.org |
| Debian/Linux Connection | Dial-up: http://www.linux.org/lessons/beginner/l17/lesson17d.html Ethernet PPPoE: http://www.linux.org/lessons/beginner/l17/lesson17c.html The splitter mentioned in this article is usually not recommended, the DSL or ADSL Modem will allow Telephone and Ethernet at the same time and on the same line. Use nothing in the line between the wall-jack and the modem unless recommended by your ISP and try to keep the distance to the wall jack to less than ten-feet, if possible. Alternately, the category 5 (cat 5) patch cord from the DSL modem to the NIC card on the back of your computer can reach about 100 feet without signal transmission problems. A Router is strongly recommended as a kind of "natural firewall", because a Hacker would generally "see" only the IP Address of the router and not the machines in your network. Also, adding computers to your network is easy with a four port or more router. A hardware or software Firewall is also strongly recommended. Cable Broadband can be networked without a router. Generally a simple hub will work; however, without a router the protection of a firewall is especially important. This Article offers more information regarding Linux Security: http://www.linuxsecurity.com/content/section/9/161/ and Linux Firewall Primer: http://www.linux.com/articles/113828?tid=100&tid=35 |
| Network administration tools | This is a good link to a list of Linux Administrator commands: http://linux.about.com/library/bl/open/newbie/blnewbie5.17.htm from the Linux Newbie Administrator Guide. (Not all commands will work with Debian). |
No need to learn vi commands if computing is your avocation: The command apt-get install ee (Debian) provides an easy to use text editor.
VI resource: https://engineering.purdue.edu/ECN/Resources/KnowledgeBase/Docs/20020202121609
| :set verbose showmode | Verbose error messages and displays current mode (command or insert). |
| ESC, i | Esc puts you in command mode, i puts you in insert mode |
| h, j, k, l | Left, down, up, right (or use the arrow keys) |
| w, W, b, B | Forward, backward by word |
| 0, $ | First, last position of current line |
| /pattern | Search forward for pattern |
| ?pattern | Search backward for pattern |
| n,N | Repeat last search in same, opposite direction |
| x | Delete character |
| dd | Delete current line |
| D | Delete to end of line |
| dw | Delete word |
| p, P | Put deleted text before, after cursor |
| u | Undo last command |
| . | Repeat the last command |
| i, a | Insert text before, after cursor [Puts you into INPUT MODE] |
| o, O | Open new line for text below, above cursor [Puts you into INPUT MODE] |
| ZZ | Save file and quit |
| :w | Save file |
| :q! | Quit, without saving changes |
Wise-Old-Blogger.com All rights reserved
Contact Webmaster@Wise-Old-Blogger.com.
Linux is a registered trademark of Linus Torvalds. All other trademarks are the property of their respective owners. |