Useful Linux Commands: Difference between revisions
(Created page with "Once you've connected, you can use these commands to use the ULYSSIS shell. First of all, whenever you need to type a longer command or filename, try the TAB key as it will t...") |
|||
(9 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
Once you've connected, you can use these commands to use the ULYSSIS shell. | Once you've connected, you can use these commands to use the ULYSSIS shell. | ||
First of all, whenever you need to type a longer command or filename, try the TAB key as it will try to complete the name of the command or file you are typing. Pressing TAB twice will show a list of possible completions. | First of all, whenever you need to type a longer command or filename, try the <code>TAB</code> key as it will try to complete the name of the command or file you are typing. Pressing <code>TAB</code> twice will show a list of possible completions. | ||
A more extensive document on this can be found at | A more extensive document on this can be found at https://info-ee.surrey.ac.uk/Teaching/Unix/. | ||
==Basic file managment== | ==Basic file managment== | ||
cd directoryname | |||
Change directory. Works the same as under MS-DOS. cd without argument changes to your home directory (like My Documents in windows). Go to the parent directory with <code>cd ..</code> | Change directory. Works the same as under MS-DOS. cd without argument changes to your home directory (like My Documents in windows). Go to the parent directory with <code>cd ..</code> | ||
ls | |||
List the contents of the current directory. Many different formats are available, a common one is <code>ls -al</code>. To accomodate MS-DOS/Windows users, <code>dir</code> is an alias (synonym) for <code>ls -alF</code>, which gives output similar to the <code>dir</code> command in MS-DOS/Windows. | List the contents of the current directory. Many different formats are available, a common one is <code>ls -al</code>. To accomodate MS-DOS/Windows users, <code>dir</code> is an alias (synonym) for <code>ls -alF</code>, which gives output similar to the <code>dir</code> command in MS-DOS/Windows. | ||
cp inputfile targetfile | |||
Copy inputfile to targetfile. Additional arguments (e.g. -r or -v are explained in the man-page.) | Copy inputfile to targetfile. Additional arguments (e.g. -r or -v are explained in the man-page.) | ||
mv inputfile targetfile | |||
Move inputfile to targetfile. Additional arguments (e.g. -i or -v are explained in the man-page.) This is the way to rename a file. Note that you cannot use a construction like mv *.htm *.html to add an ``l'' to a bunch of files. A small shell script can provide a way to do this: <code>for i in *.htm; do mv i; done</code> | Move inputfile to targetfile. Additional arguments (e.g. -i or -v are explained in the man-page.) This is the way to rename a file. Note that you cannot use a construction like mv *.htm *.html to add an ``l'' to a bunch of files. A small shell script can provide a way to do this: <code>for i in *.htm; do mv i; done</code> | ||
rm filename | |||
Remove filename. Additional arguments (e.g. -r or -v are explained in the man-page.) Note: there is no undelete-alike function in most unices. | Remove filename. Additional arguments (e.g. -r or -v are explained in the man-page.) Note: there is no undelete-alike function in most unices. | ||
mkdir dirname | |||
Creates a directory called dirname. | Creates a directory called dirname. | ||
rmdir dirname | |||
Removes an empty directory. Use rm -r to delete a directory and recursively everything in it. Add -f to disable any prompts (dangerous!). | Removes an empty directory. Use rm -r to delete a directory and recursively everything in it. Add -f to disable any prompts (dangerous!). | ||
==Getting help== | ==Getting help== | ||
man command-name | |||
Displays manual pages, if available. E.g. man ls. Use 'q' to exit. Relatives: apropos, help. | Displays manual pages, if available. E.g. man ls. Use 'q' to exit. Relatives: apropos, help. | ||
apropos word | |||
Searches through headers of all man pages. | Searches through headers of all man pages. | ||
help command-name | |||
Displays help about command-name. Only for internal bash-functions. | Displays help about command-name. Only for internal bash-functions. | ||
bash | |||
The Bourne Again SHell. Widely used successor of sh, the Bourne shell. This is the program you're working under after you open a ssh-session (you don't have to start it to use it). Bash interprets your commands, and executes them. Tab-completion, * and ? expansions, etc are all bash functions. man bash will give you tons of info about it. Alternatives : tcsh, zsh, rc | The Bourne Again SHell. Widely used successor of sh, the Bourne shell. This is the program you're working under after you open a ssh-session (you don't have to start it to use it). Bash interprets your commands, and executes them. Tab-completion, * and ? expansions, etc are all bash functions. man bash will give you tons of info about it. Alternatives : tcsh, zsh, rc | ||
Line 57: | Line 57: | ||
It's easier to use a text editor on a server, than editing your file locally and uploading that file. | It's easier to use a text editor on a server, than editing your file locally and uploading that file. | ||
nano | |||
Probably the easiest text editor. Should be self-explanatory. | Probably the easiest text editor. Should be self-explanatory. The symbol ^ is used for the ctrl key and M- stands for alt. | ||
vim | |||
Probably the best text editor. Start editing by pressing i. Stop editing by pressing the escape key. Save and quit with :wq. Quit without saving with :q!. | |||
Probably the best text editor. Start editing by pressing | |||
==Utilities== | ==Utilities== | ||
df | |||
Displays info about the free diskspace on the system. df . will give info about the filesystem where the current directory resides. The output becomes a bit more readable with the -h switch. | Displays info about the free diskspace on the system. df . will give info about the filesystem where the current directory resides. The output becomes a bit more readable with the -h switch. | ||
du | |||
Displays info about the diskusage in the current directory (and its subdirectories. A common parameter is -s , equivalent to -summarize , to summarize the disk-usage (without the per-subdir totals). | Displays info about the diskusage in the current directory (and its subdirectories. A common parameter is -s , equivalent to -summarize , to summarize the disk-usage (without the per-subdir totals). | ||
quota | |||
Displays info about your diskusage, and your disk quota. Quota are limits on diskusage, imposed by the system administrator. The system will warn you if you exceed these limits. | Displays info about your diskusage, and your disk quota. Quota are limits on diskusage, imposed by the system administrator. The system will warn you if you exceed these limits. | ||
ps | |||
Displays info about processes. Various options possible, for example ps auxf gives info on all processes, including process owner, memory usage, and parent-child indication. | Displays info about processes. Various options possible, for example ps auxf gives info on all processes, including process owner, memory usage, and parent-child indication. | ||
htop | |||
Displays top CPU processes. Use it to see what gets most cpu power at the moment. Don't leave top open for a long time, since it eats cpu time itself. (quit with 'q'). | Displays top CPU processes. Use it to see what gets most cpu power at the moment. Don't leave top open for a long time, since it eats cpu time itself. (quit with 'q'). | ||
[[Category:Shell]] |
Latest revision as of 13:40, 31 August 2024
Once you've connected, you can use these commands to use the ULYSSIS shell.
First of all, whenever you need to type a longer command or filename, try the TAB
key as it will try to complete the name of the command or file you are typing. Pressing TAB
twice will show a list of possible completions.
A more extensive document on this can be found at https://info-ee.surrey.ac.uk/Teaching/Unix/.
Basic file managment
cd directoryname
Change directory. Works the same as under MS-DOS. cd without argument changes to your home directory (like My Documents in windows). Go to the parent directory with cd ..
ls
List the contents of the current directory. Many different formats are available, a common one is ls -al
. To accomodate MS-DOS/Windows users, dir
is an alias (synonym) for ls -alF
, which gives output similar to the dir
command in MS-DOS/Windows.
cp inputfile targetfile
Copy inputfile to targetfile. Additional arguments (e.g. -r or -v are explained in the man-page.)
mv inputfile targetfile
Move inputfile to targetfile. Additional arguments (e.g. -i or -v are explained in the man-page.) This is the way to rename a file. Note that you cannot use a construction like mv *.htm *.html to add an ``l to a bunch of files. A small shell script can provide a way to do this: for i in *.htm; do mv i; done
rm filename
Remove filename. Additional arguments (e.g. -r or -v are explained in the man-page.) Note: there is no undelete-alike function in most unices.
mkdir dirname
Creates a directory called dirname.
rmdir dirname
Removes an empty directory. Use rm -r to delete a directory and recursively everything in it. Add -f to disable any prompts (dangerous!).
Getting help
man command-name
Displays manual pages, if available. E.g. man ls. Use 'q' to exit. Relatives: apropos, help.
apropos word
Searches through headers of all man pages.
help command-name
Displays help about command-name. Only for internal bash-functions.
bash
The Bourne Again SHell. Widely used successor of sh, the Bourne shell. This is the program you're working under after you open a ssh-session (you don't have to start it to use it). Bash interprets your commands, and executes them. Tab-completion, * and ? expansions, etc are all bash functions. man bash will give you tons of info about it. Alternatives : tcsh, zsh, rc
Text editors
It's easier to use a text editor on a server, than editing your file locally and uploading that file.
nano
Probably the easiest text editor. Should be self-explanatory. The symbol ^ is used for the ctrl key and M- stands for alt.
vim
Probably the best text editor. Start editing by pressing i. Stop editing by pressing the escape key. Save and quit with :wq. Quit without saving with :q!.
Utilities
df
Displays info about the free diskspace on the system. df . will give info about the filesystem where the current directory resides. The output becomes a bit more readable with the -h switch.
du
Displays info about the diskusage in the current directory (and its subdirectories. A common parameter is -s , equivalent to -summarize , to summarize the disk-usage (without the per-subdir totals).
quota
Displays info about your diskusage, and your disk quota. Quota are limits on diskusage, imposed by the system administrator. The system will warn you if you exceed these limits.
ps
Displays info about processes. Various options possible, for example ps auxf gives info on all processes, including process owner, memory usage, and parent-child indication.
htop
Displays top CPU processes. Use it to see what gets most cpu power at the moment. Don't leave top open for a long time, since it eats cpu time itself. (quit with 'q').