User Tools

Site Tools


sysadmin:linux:basic_commands

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
sysadmin:linux:basic_commands [2025/12/16 02:38] mlivolsisysadmin:linux:basic_commands [2025/12/16 03:09] (current) mlivolsi
Line 6: Line 6:
 |more filename | shows the first part of a file, just as much as will fit on one screen. Just hit the space bar to see more or q to quit. You can use /pattern to search for a pattern. | |more filename | shows the first part of a file, just as much as will fit on one screen. Just hit the space bar to see more or q to quit. You can use /pattern to search for a pattern. |
  
-|head filename show me the first lines of a file  +|head filename show me the first lines of a file | 
-|tail filename -  show me the last lines of a file +|tail filename show me the last lines of a file | 
-|vi filename Another editor (preferred)  +|vi filename Another editor (preferred) | 
-|mv filename1 filename2 --- moves a file (i.e. gives it a different name, or moves it into a  different directory (see below) (dos equivalent of rename) +|mv filename1 filename2 moves a file (i.e. gives it a different name, or moves it into a different directory (see below) (dos equivalent of rename) | 
-|cp filename1  filename2 --- copies a file (dos equivalent of copy) +|cp filename1 filename2 copies a file (dos equivalent of copy) | 
-|rm filename --- removes a file. It is wise to use the option rm -i, which will ask  you for confirmation before actually deleting anything. You can make  this your default by making an alias in  your .cshrc file. (dos equivalent of erase) +|rm filename removes a file. It is wise to use the option rm -i, which will ask you for confirmation before actually deleting anything. You can make this your default by making an alias in your .cshrc file. (dos equivalent of erase) | 
-|diff filename1 filename2 |  compares files, and shows where they differ |+|diff filename1 filename2 | compares files, and shows where they differ |
 |wc filename      | tells you how many lines, words, and characters there are in a file | |wc filename      | tells you how many lines, words, and characters there are in a file |
-|chmod options filename |lets you change the read, write, and execute permissions on your  files. The default is that only you can look at them and change  them, but you may sometimes want to change these permissions. For  example, chmod  o+r filename will  make the file readable for everyone, and chmod  o-r filename will make it unreadable for others again. Note that for someone to be  able to actually look at the file the directories it is in need to  be at least executable. See help  protection for  more details.|+|chmod options filename |lets you change the read, write, and execute permissions on your files. The default is that only you can look at them and change them, but you may sometimes want to change these permissions. For example, chmod o+r filename will make the file readable for everyone, and chmod o-r filename will make it unreadable for others again. Note that for someone to be able to actually look at the file the directories it is in need to be at least executable. See help protection for more details.|
 |tar –cvf filename.tar | Make a non-compressed aggregate of files| |tar –cvf filename.tar | Make a non-compressed aggregate of files|
 |tar –xvf filename.tar | Extract files out (files are known as ‘tarballs’)| |tar –xvf filename.tar | Extract files out (files are known as ‘tarballs’)|
  
-File  Compression+**File Compression**
     
-gzip filename --- compresses files, so that they take up much less space. Usually  text files compress to about half their original size, but it depends very much on the size of the file and the nature of the  contents. There are other tools for this purpose, too  (e.g. compress),  but gzip usually gives the highest compression rate. Gzip produces  files with the ending '.gz' appended to the original filename.  +gzip filename compresses files, so that they take up much less space. Usually text files compress to about half their original size, but it depends very much on the size of the file and the nature of the contents. There are other tools for this purpose, too (e.g. compress), but gzip usually gives the highest compression rate. Gzip produces files with the ending '.gz' appended to the original filename.| 
-gunzip filename --- uncompresses files compressed by gzip. +gunzip filename uncompresses files compressed by gzip.| 
-  +gzcat filename lets you look at a gzipped file without actually having to gunzip it (same as gunzip  -c). You can even print it directly, using gzcat filename | lpr  
-gzcat filename --- lets you look at a gzipped file without actually having to gunzip  it (same as gunzip  -c).  You can even print it directly, using gzcat filename |  lpr  + 
-Directories +**Directories** 
- mkdir dirname --- make a new directory + 
-cd dirname --- change directory. You basically 'go' to another directory, and you  will see the files in that directory when you do 'ls'. You always  start out in your 'home directory', and you can get back there by  typing 'cd' without arguments. 'cd ..' will get you one level up  from your current position. You don't have to walk along step by  step - you can make big leaps or avoid walking around by  specifying pathnames.  +mkdir dirname make a new directory | 
-pwd --- tells you where you currently are. +cd dirname change directory. You basically 'go' to another directory, and you will see the files in that directory when you do 'ls'. You always start out in your 'home directory', and you can get back there by typing 'cd' without arguments. 'cd ..' will get you one level up from your current position. You don't have to walk along step by step - you can make big leaps or avoid walking around by specifying pathnames.| 
-Finding things+pwd tells you where you currently are.
 + 
 +**Finding things**
    
-find  --- find files anywhere on the system. This can be extremely useful if  you've forgotten in which directory you put a file, but do remember  the name. (ie. find  . –name foo.bar –print   +|find |find files anywhere on the system. This can be extremely useful if you've forgotten in which directory you put a file, but do remember the name. (ie. find . –name foo.bar –print )|  
-  +|grep string filename(s) looks for the string in the files. This can be useful a lot of purposes, e.g. finding the right file among many, figuring out which is the right version of something, and even doing serious corpus work. grep comes in several varieties (grep, egrep, and fgrep) and has a lot of very flexible options. Check out the man pages if this sounds good to you.|
-grep string filename(s) --- looks for the string in the files. This can be useful a lot of  purposes, e.g. finding the right file among many, figuring out which  is the right version of something, and even doing serious corpus work. grep comes in several varieties (grep, egrep,  and fgrep)  and has a lot of very flexible options. Check out the man pages if  this sounds good to you. +
-About other people  +
-w --- tells you who's logged in, and what they're doing. Especially useful: the 'idle' part. This allows you to see whether they're actually sitting there typing away at their keyboards right at the moment.+
  
-who --- tells you who's logged on, and where they're coming from. Useful if you're looking for someone who's actually physically in the same building as you, or in some other particular location.  +**About other people**
-finger username --- gives you lots of information about that user, e.g. when they last read their mail and whether they're logged in. Often people put other practical information, such as phone numbers and addresses, in a file called .plan. This information is also displayed by 'finger'+
  
-last -1 username --- tells you when the user last logged on and off and from where Without any options, last will give you a list of everyone's logins+|w |tells you who'logged in, and what they're doingEspecially useful: the 'idle' part. This allows you to see whether they're actually sitting there typing away at their keyboards right at the  moment.| 
-About your (electronic) self +|who |tells you who's logged on, and where they're coming fromUseful if you're looking for someone who's actually physically in the same building as you, or in some other particular location.| 
-whoami --- returns your username. Sounds useless, but isn't. You may need to find out who it is who forgot to log out somewhere, and make sure *you* have logged out.  +|finger username | gives you lots of information about that usere.g. when they last read their mail and whether they're logged in. Often people put other practical informationsuch as phone numbers and addresses, in a file called .plan. This information is also displayed by 'finger'| 
-finger   +|last -1 username | tells you when the user last logged on and off and from whereWithout any optionslast will give you a list of everyone's logins.|
- of course you can finger yourself, too. That can be useful e.g. as a quick check whether you got new mail. Try to create a useful .plan file soon. Look at other people's .plan files for  ideas. The file needs to be readable for everyone in order to be visible through 'finger'. Do 'chmod a+r .plan' if necessary. You should realize that this information is accessible from anywhere in  the world, not just to other people on turing. +
-passwd --- lets you change your passwordwhich you should do regularly (at least once a year). See the LRB guide and/or  look at help password+
-ps -u yourusername --- lists your processes.  +
-kill PID --- kills (ends) the processes with the ID you gave. This works only for your own processes, of course. Get the ID by using ps. If the process doesn't 'die' properly, use the option -9. But attempt without that option firstbecause it doesn't give the process a chance to finish possibly important business before dying You may need to kill processes for example if your modem connection was interrupted and you didn't get logged out properlywhich sometimes happens. +
-du filename --- shows the disk usage of the files and directories in filename (without argument the current directory is used). du -s gives only total+
-df –k – Available space on all storage devices +
-last yourusername --- lists your last loginsCan be a useful memory aid for when you were wherehow long you've been working for, and keeping track of your phonebill if you're making a non-local phonecall for dialling in. +
-Connecting to the outside world +
  
 +**About your (electronic) self**
  
-ssh –l username hostname --- also lets you connect to a remote host. Use rlogin whenever  possible. +|whoami | returns your username. Sounds useless, but isn't. You may need to find out who it is who forgot to log out somewhere, and make sure *you* have logged out.| 
-  +|finger | of course you can finger yourself, too. That can be useful e.g. as a quick check whether you got new mail. Try to create a useful .plan file soon. Look at other people's .plan files for ideas. The file needs to be readable for everyone in order to be visible through 'finger'. Do 'chmod a+r .plan' if necessary. You  should realize that this information is accessible from anywhere in the world, not just to other people on turing.| 
-sftp username@hostname --- lets you download files from a remote host. This is a common method  for exchanging files. The most important commands within sftp  are get for  getting files from the remote machine, and put for  putting them there   +|passwd | lets you change your password, which you should do regularly (at least once a year). See the LRB  guide and/or look at help password.| 
-  +|ps -u yourusername | lists your processes. | 
-lynx --- lets you browse the web from an ordinary terminal. (not always available) +|kill PID | kills (ends) the processes with the ID you gave. This works only for your own processes, of course. Get the ID by using ps. If the process doesn't 'die' properly, use the option -9. But attempt without that option first, because it doesn't give the  process a chance to finish possibly important business before dying. You may need to kill processes for example if your modem connection was interrupted and you didn't get logged out properly, which sometimes happens.| 
-Miscellaneous  tools  +|du filename | shows the disk usage of the files and directories in filename (without argument the current directory is used). du -s gives only a total.| 
-date --- shows the current date and time. +|df –k | Available space on all storage devices | 
-cal --- shows a calendar of the current month. Use e.g., 'cal 10 1995' to  get that for October 95, or 'cal 1995' to get the whole year.  +|last yourusername | lists your last logins. Can be a useful memory aid for when you were where, how long you've been working for, and keeping track of your phonebill if you're making a non-local phonecall for dialling in.| 
-bc basic calculator (control-d to quit)  + 
-man  - (manual) get help on a topic  +**Connecting to the outside world ** 
-top show processes, memory and cpu (control –c to quit)  + 
-uname –a  – Name and operating system of the machine I’m on+|ssh –l username hostname | also lets you connect to a remote host. Use rlogin whenever possible.| 
 +|sftp username@hostname lets you download files from a remote host. This is a common method for exchanging files. The most important commands within sftp are get for getting files from the remote machine, and put for putting them there | 
 +|lynx lets you browse the web from an ordinary terminal. (not always available) | 
 + 
 +**Miscellaneous tools ** 
 + 
 +|date shows the current date and time.| 
 +|cal shows a calendar of the current month. Use e.g., 'cal 10 1995' to get that for October 95, or 'cal 1995' to get the whole year.| 
 +|bc  basic calculator (control-d to quit) | 
 +|man  (manual) get help on a topic | 
 +|top  show processes, memory and cpu (control –c to quit) 
 +|uname –a Name and operating system of the machine I’m on |
  
 You can find out more about these commands by looking up their manpages:  You can find out more about these commands by looking up their manpages: 
- man commandname --- shows you the manual page for the command+ 
 +man commandname --- shows you the manual page for the command
  
  
sysadmin/linux/basic_commands.1765852703.txt.gz · Last modified: by mlivolsi