There are a few pages to go along with this - please see under "Linux info for Undergrads" in the menu on the left.
- First steps
- Finding your way around
- Changing directory
- A note about the differences between Linux and Windows text files
- Linux file paths
- Echoes, pipes and command logic
- Creating files and directories
- Viewing files - more or less
- File manipulation
- Some other useful commands
- Going beyond the basics
So, you've suddenly found yourself in one of the Physics units that uses linux. Probably either 'programming skills' or 'computational physics' - you've managed to log in to the servers by following the instructions, and what do you see?
Helpful, isn't it? No menus, no icons, nothing. So, it's time to find out a few things. For a start, where are we? The prompt (known in this case as the 'BASH prompt') on the left is of little help. When you first login you'll be in your 'home directory' on one of our servers - the home directory is your top level, and is the equivalent of the Windows h:\ drive - any file you can see directly in h:\ will be here at the top level in your home directory.
Finding your way around
The first thing we'll do is see exactly what is here. To do this we want a 'directory listing' and the command for this is 'ls', like this:
and yours will probably look similar to that. Some of the names shown will be files, some will be directories, but it may not be easy to see. To help a bit we'll add a 'flag' to the ls command, to ask for more information. In this case using 'ls -l' will produce a 'long listing' which is a bit more helpful:
Panic! A lot of almost indecipherable information! Let's break it down a bit, by looking at just one line:
Or to split it out a bit into more obvious columns:
Sep 28 2009
File permissions (a big subject), with the d at the start showing this is a directory
Number of links (ignore!)
The owner user (related to permissions)
The owner group (permissions again)
File size in bytes - think of 4096 as a dummy value for directories
File timestamp (last edited or time created) - shows year instead of time if that's more relevant
The file/directory name
So, a lot of information, much of it related to permissions.
So, you have this list of directories in front of you - how do you get into one of them? Simple, you 'change directory', using the 'cd' command. i.e. to change into the 'dos' directory (which happens to be "My Documents" on the Windows PCs):
I think it's worth mentioning at this point that linux is case sensitive, so you need to ensure you get your upper and lower case characters correct.
A note about the differences between Linux and Windows text files
If you start transferring text files (i.e. program code, or output) between Windows and UNIX you'll soon hit some problems, as they treat the end of a line of text differently.
For historical reasons Windows (based on the dos format) finishes text lines using the ASCII codes for both 'New Line' and 'Carriage Return' - and UNIX just uses 'New Line'
Windows text editors, including Notepad, get confused when they don't see the 'Carriage Return' at the end of a line, and tend to run all of the text together. UNIX editors (pico, vi, emacs etc) are generally better behaved, and don't complain too much if they get a windows style carriage return command at the end of a line - compilers however don't like it much.
So, what can you do about this - well, you could just stick to using UNIX tools to do all of the work, or you can use a text editor on Windows that understands UNIX text files (Notepad++ or TextPad are my favourites), or you can use some tools installed on the campus UNIX servers to convert the files for you
Converting text files using dos2unix and unix2dos
There are 2 commands that you need, depending on which way you're going (and you need to specify that we're using ASCII - you don't need to know what that means!):
If you're taking a file you've created in Windows (in dos format), to use in UNIX, you should use 'dos2unix'
(where 'test.txt' is the name of the Windows text file)
If you're taking a file you've created in UNIX, to use in Windows, you should use 'unix2dos'
Linux file paths
Explain the meaning of the paths - i.e. home, /, ~/dos etc.
Echoes, pipes and command logic
>>, >, |, !, !!, &, &&, < and << all handy to know about.
Creating files and directories
mkdir, touch, pwd, rmdir, rm, find etc.
Viewing files - more or less
cat, more, less
grep, wc, wc -l, sort, head and tail. If brave, sed and awk!
Some other useful commands
ps, chmod, chown, find, quota, du, kill
Going beyond the basics
jobs, fg, bg etc. Screen?