tutorials:2
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
tutorials:2 [2022/09/26 23:12] – ↷ Page moved from tardis_beginner_tutorials:2 to tutorials:2 tcmal | tutorials:2 [2023/04/03 11:49] – tcmal | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== 2. Using the command line ====== | ||
- | ======= Tutorial 2: Basic navigation of the command line environment ======= | ||
+ | When you log in via SSH, you are presented with the command line interface, by means of the shell. | ||
+ | The current default is Bash. Bash stands for " | ||
+ | A shell is is what interprets what you type into the prompt and makes things happen - different shells do things differently. | ||
+ | Your default shell is bash, although you can change it if you wish, but this document will only give you a brief introduction to using the shell to run programs and use the filesystem. | ||
- | When you log in via SSH, you are presented with the command line interface, by means of the shell. | + | ===== The Prompt ===== |
- | ===== Prevent | + | The first thing you should notice is that your shell puts something at the start of every line. This is called the prompt and it looks something like this: |
+ | < | ||
+ | tcmal@sontaran: | ||
+ | </ | ||
- | Since Linux is a Unix-like system, it inherits many features from Unix's design. On multi-user systems, this includes having everyone's home directories | + | The default prompt tells us our username ('' |
- | This may not be desirable to you, especially if you use your shell account for idling on IRC all day, and have a few private messages you might not want everyone to be able to see (however, note, do not have an expectation of privacy on insecure, multi-user systems). | + | |
- | In the shell, type **chmod -R o-rwx ~** | + | We can enter commands after the prompt, hit enter, and once they' |
- | The tilde '~' is shorthand for your home directory, | + | < |
+ | tcmal@sontaran: | ||
+ | tcmal | ||
+ | tcmal@sontaran: | ||
+ | sontaran.tardisproject.uk | ||
+ | tcmal@sontaran: | ||
+ | /home/tcmal | ||
+ | </code> | ||
- | ===== Running programs ===== | + | While you're at your prompt, you can also use the arrow keys to scroll back up your command history, and Ctrl+R to search through it. |
+ | ===== Moving around ===== | ||
- | To run a program, you need to know the name of that program. All you need to do is type that name, or if it is a specific script or program in a non-standard place, you will need to type the path of it as well (more on this later). A lot of the non-interactive Linux programs take command-line options which are additional words or filenames you type after the name of the program. For example, the Linux program **cat** (short for " | + | As mentioned above, our current directory |
- | **< | + | |
- | This simply dumps the content of the file " | + | |
- | Try typing **ls /** | + | |
- | Now try typing **ls / -l** | + | |
- | This simply lists the files and directories | + | |
- | It is worth mentioning that the Linux command-line is case sensitive, unlike windows - this means that **cat** is different from **CAT** and from **Cat** etc. - only one will work, because there is no program called " | + | |
+ | We can use '' | ||
- | ===== Learning how to use programs ===== | + | < |
+ | tcmal@sontaran: | ||
+ | tcmal@sontaran:/ | ||
+ | tcmal@sontaran: | ||
+ | </ | ||
+ | This is more interesting if we make some directories, | ||
- | The best way to learn how a program works and how to use it is by reading the man page (manual page) built into the system about that program. To find out what a program does and how to use it, simply type man [program name]. Try it now - type: | + | < |
- | **< | + | tcmal@sontaran: |
- | You can scroll up and down using up and down arrows, page up and page down, and space and return. Don't worry if you don't understand everything written there, you're not expected to memorize all of a program' | + | tcmal@sontaran: |
+ | tcmal@sontaran: | ||
+ | tcmal@sontaran: | ||
+ | tcmal@sontaran: | ||
+ | / | ||
+ | tcmal@sontaran: | ||
+ | tcmal@sontaran:~/test$ | ||
+ | </ | ||
- | I should also mention the other manual command, info which (most of the time) shows the same info as man, but uses Emacs to display it. However, certain programs (such as tar) have much more useful information | + | '' |
+ | We can use '' | ||
- | ===== Finding a program for your purpose ===== | + | < |
+ | tcmal@sontaran: | ||
+ | tcmal@sontaran: | ||
+ | test2 test3 | ||
+ | tcmal@sontaran: | ||
+ | total 16 | ||
+ | drwxr-xr-x 4 tcmal 1004 4096 Oct 26 22:49 . | ||
+ | drwxr-xr-x 7 tcmal 1004 4096 Oct 26 22:49 .. | ||
+ | drwxr-xr-x 2 tcmal 1004 4096 Oct 26 22:49 test2 | ||
+ | drwxr-xr-x 2 tcmal 1004 4096 Oct 26 22:49 test3 | ||
+ | </ | ||
+ | As well as // | ||
+ | In '' | ||
- | If you know what sort of program you want to run, but aren't sure of the name (or if such a program exists), you can use **apropos** to search for a program by function. For instance, say we want to find an IRC client but we don't know the names of any. We type: | + | Now that we know how to make directories, lets clean up after ourselves. Replace ''<username>'' |
- | **<code>apropos irc</ | + | |
- | But we get quite a lot of matches, most of which are no use to us. This is because the search has turned up a load of results where " | + | |
- | **< | + | |
- | Yay, we've narrowed our matches down to what we wanted! Alternatively we could have tried **apropos "irc client" | + | |
+ | < | ||
+ | tcmal@sontaran: | ||
+ | tcmal@sontaran: | ||
+ | tcmal@sontaran: | ||
+ | </ | ||
- | ===== Navigating | + | Note that we gave '' |
+ | When we call '' | ||
+ | The recursive flag is needed when you're deleting directories - like most long flags there is a corresponding short flag, so we could have said '' | ||
- | Just like in windows, you can use **cd** | + | ===== Learning how to use programs ===== |
- | To go up a step in the directory tree type cd .. | + | |
- | Notice you are now in the /home/ directory with all the users' home directories. To return to your specific home directory, type **cd [your username]** | + | |
- | To go to the root of the filesystem type **cd /** | + | |
- | You can also use tab completion - this is where you press tab partway through typing the name of the directory (or filename) and the shell completes it for you (if there is only one possible match). Otherwise you will hear a beep. If you press tab a second time, it will list all the possible completions for what you've typed already. Type **cd ~** to return to your home directory. | + | |
- | You can navigate faster by using absolute paths. The current directory can be printed to the shell by typing **pwd** - this is useful to remember for scripts that you write for the shell. If you wanted to look at the source of my web page, you could type: | + | |
- | **< | + | The best way to learn how a program works and how to use it is by reading |
- | cd .. | + | |
- | cd .. | + | |
- | cd var | + | |
- | cd autofs | + | |
- | cd www | + | |
- | cd users | + | |
- | cd rain | + | |
- | cd pages | + | |
- | </ | + | |
- | But it is infinitely more efficient to type **cd / | + | |
- | All this takes a little getting used to, and it's useful | + | This takes us away from our shell and into a **pager**. You can scroll up and down using up and down arrows, page up and page down, and space and return. Don't worry if you don't understand everything written there, you're not expected |
+ | ===== Finding a program for your purpose ===== | ||
- | ===== Changing your shell ===== | + | If you know what sort of program you want to run, but aren't sure of the name (or if such a program exists), you can use **apropos** to search for a program by function. For instance, say we want to find an IRC client but we don't know the names of any. We type: '' |
+ | But we get quite a lot of matches, most of which are no use to us. This is because the search has turned up a load of results where " | ||
- | If you decide you want to try another shell, you can type the name of it, e.g. **zsh** (Z Shell) to start it. However, | + | Yay, we've narrowed our matches down to what we wanted! Alternatively we could have tried '' |
- | **Next: [[tardis_beginner_tutorials: | ||