Основни Команди Linux

From Ilianko

adduser


A list of common commands is very useful when new to Debian, to teach you how to handle/manage files and systems.I extracted from Debian’s User Reference Manual the most often used commands :

Commands for reading documentation:

man [section-number] subject man shows the manual page on the command (use q or ctrl-C to get out of it if it doesn’t terminate at the end of the text) This command is crucial for helping you learn how to use it and other Linux commands


info [subject] A lot of Debian Linux documentation is provided in info format. This is similar to a hypertext format, in that you can jump to other sections of the documentation by following links embedded in the text.

help [subject] Use help for on-line help about bash’s built-in commands. Help by itself prints a list of subjects for which you can ask for help.

Commands for basic file-handling:

If you are gonna use linux as operating system you have to know this commands: pwd Show the current directory.

cd [directory] Change your current directory to the named directory. If you don’t specify directory, you will be returned to your home directory.

mkdir new_directory mkdir is used to create a new directory. new_directory can be specified as a path, or as a simple name (in which case it is created in the current directory).

mv source target mv moves source file to target and deletes source; source can be a list of files, but in that case target must be a directory.This is also the way to rename a file or directory.

cp source target cp copies source to target. Again, target can be a directory and source a list of files.

ln source target ln links source to target with hard or symbolic links according to the options.

rm filelist rm deletes files. With the -r option it can delete directories and their contents.Be very careful with rm; once a file is deleted, you cannot get it back. There is no undelete command.

rmdir directorylist rm deletes empty directories.

chmod mode filelist chmod changes the permissions of files and directories. The mode is either an octal number, such as 644, or a symbolic representation of it, such as u=rw,go=r.

chown owner[.group] filelist chown changes the ownership of files. Use the -R option to do this for an entire directory tree.

If .group is specified as well as owner, the group ownership of the files is changed as well.

chgrp group filelist chgrp changes the group ownership of files. Use the -R option to do this for an entire directory tree.

ls directory ls lists the contents of directory; by default, the output is sorted.There are more options to ls than to any other command. Those most commonly used are -l, to show the file permissions and the latest change date and -a, to show hidden dot-files.

Commands for managing file-systems:

df df lists mounted partitions and shows the amount of space present, used and available. (The partitions will probably include /proc, which is a special `non-existent’ partition, that contains information about the current state of the Linux kernel.)

mount [partition directory] mount by itself lists mounted partitions.It is also the command to use to add a partition’s file-system into the universal directory tree. For example: mount /dev/hda2 /usr You have to be superuser (log in as root or run su) in order to mount or unmount file-systems.

umount directory umount removes a partition’s file-system from the universal directory tree. For example: umount /usr

You have to be superuser (log in as root or run su) in order to mount or unmount file-systems.

Commands for Looking at files:

cat textfile[s] cat dumps textfile[s] to screen without paging (like DOS’s type). If you name more than one file, each will be sent in order, with no break or heading.

more textfile[s] more lists the textfile[s] to the screen in pages so that you can read it. Press Space-bar to move on one page, Enter to move on one line, and b to move back one page. Use q or ctrl-c to quit; more will quit automatically when it gets to the end of the last file.

less textfile[s] less is like more but has more features and somewhat different behaviour. You have to type Q to terminate it.

head textfile[s] head is used to see the first few lines of a file (by default, it shows 10 lines).

tail textfile[s] tail is used to see the last few lines of a file (by default, it shows 10 lines).so for example if you want to see live your apache access.log file to see who is accessing your website you can type tail -f /var/log/apache2/access.log

find directory -name filename find tells you where filename is in the tree starting at directory. This command has many other useful options.

grep pattern filelist grep scans each file in filelist for lines which match pattern

file file file reports what kind of thing file is.

type file type says where to find file in your search path.

whereis file whereis is like type, but gives more information.

Commands for Session management:

exit or logout Use exit or logout to terminate your session and log out. All jobs you have started are terminated, unless they were started with nohup, and your screen should return you to the log-in prompt. You can often use Ctrl-D to do the same, but that capability can be disabled.

su Use su to become superuser. You will be asked to enter a password; this is the password for the root login.Becoming superuser is almost the same as logging in as root. You get the same power to do damage. Be very careful!

Use exit, logout or ctrl-D to stop being superuser.

bg and fg If you are running one job and want to run something else in the same screen without stopping the first job, you can put the first job in the background by typing Ctrl-Z. You can then run other commands. You can start the first job running again in the background by using bg. It will continue to run in the background until it wants to send anything to the screen; then it will stop and wait. You can bring it forward again and let it continue by using the command fg.

script file Use script to record everything that appears on the screen (until the next exit) in file. This is useful if you need to record what’s going on in order to include it in your message when you ask for help. Use exit, logout or ctrl-D to stop the recording session.

ps Use ps to list your processes. You can also use ps to see all processes on the system: ps -ax The number in the column headed PID is the identifying number of the process. Under column TT is the tty (screen or window identifier) where it is running. A question mark here means that it is not attached to any screen or window, but is running in the background.

tty tty shows you which terminal (screen or window) you are in. tty /dev/ttyp4

These commands relate to your identity as a user and the machine’s own identity:

passwd Use passwd to change the password that you use when you log in. Follow the instructions on screen about what kind of password to choose. When you type the password in, it doesn’t show on the screen, so you have to enter it twice, to ensure that you make no typing errors.

id id tells you what user you are and what group you are in.

id uid=1000(olly)gid=1000(olly)groups=1000(olly),6(disk),20(dialout),25(floppy),26(tape),29(audio),34(backup),37 (operator),101(priory) uid indicates your user number, gid your group number (which will be assigned to files that you create) and groups lists the other groups that you are a member of.

who -u who -u reports everyone who is logged on.

uname -a uname -a reports the name, type and operating system of your machine.

date date reports the current time and date. The superuser can use this command to set the date and time.

Commands for Turning off the computer:

Turning the computer on and off is really a system administration subject, but I include it here because it is something that every user who is his own administrator needs to know. If someone else is responsible for administering the machine, you should neither need nor be able to shut it down.

shutdown -t 0 -h now This command shuts the computer down safely. You can also use ctrl-alt-del if your system is set up for that. (If you are in X, ctrl-alt-del will be intercepted by X. Get out of X first by using ctrl-alt-backspace.) Never turn off a Unix machine without doing a safe shutdown: if you do, you will damage your file-systems.