Catch up on stories from the past week (and beyond) at the Slashdot story archive

 



Forgot your password?
typodupeerror
×
User Journal

Journal bennett000's Journal: *NIX crash course

This is a crash course in *NIX CLI usage I just gave a friend.

*NIX Command Line in a nutshell, including stuff you already know, that I'm including for future copy/paste purposes. I'll try and keep it concise:

UNIX/Linux/GNU/BSD, and even Macs are all systems that share some common low-level-interface commonalities. This isn't to say they operate the same way, they just present the user with a somewhat consistent 'view' of how your computer's internals relate to each other. Given this consistent 'view' or abstraction applications like shells can operate consistently across the platforms. (Abstraction is critical to every level of elegant computing, but that's a whole other story)

Shells provide the user an interface to the computer. CLIs are a subset of shells, and provide a language oriented interface to the computer. GUIs of course are also a subset of shells, and provide an audio/visual interface to the computer. This discussion will of course be concerned with the CLI subset.

CLIs evolved out of Victorian era telegraphing principles, notably early stock tickers. Communications pushed these machines further, as code breaking machines started turning into computers during the early to mid twentieth century, the CLI was 'born' with the 1950s teletype machine. Teletypes evolved into terminals, through batch processes, and eventually UNIX. Despite the early eighties breakup of Ma Bell, UNIX / C, and its principles have continued to exercise a massive influence on computing.

Modern CLIs fall into four categories, Bourne Shell derivatives, C shell derivatives, Windows/DOS command prompt, and other. Bourne Shell descendants make up every single default Shell, on every open source operating system I've ever used. That's not to say there isn't merit to the C-Shell, Windows/DOS, and the others, but given their prevalence, we'll be discussing Bourne derivatives.

Before diving into the nuts and bolts of a Bourne style CLI, it's important to have an idea of how a typical *NIX system is laid out. Typical *NIX systems are made up of a file system that represents everything from a spreadsheet to a web-camera. Remote files can often be referenced straight from the CLI, just by providing a URI.

The most common root folders on a *NIX system: /boot /etc /usr /bin /var /tmp, /home /home/*user*/.xxx /mnt /dev

Most *NIX systems have other folders too, but these are the most common. *NIX systems aspire to be highly organized, but it's not uncommon for them to become convoluted, like Windows can be. /boot stores all the stuff your computer needs to boot up. In DOS terms, this would be autoexec.bat, config.sys, msdos.sys, command.com... In *NIX terms, it often has the kernel, and boot-loader /etc stores all of the system, and service/server/daemon configuration files. /etc usually is divided into sub folders that pertain to the complexities of web server configs, boot scripts, cron (scheduler) tasks, remote shell (SSH) configs, proxy settings, etc! /usr contains the system's primary application data. /usr usually has a /usr/local sub folder for user specific applications. /usr, and /usr/local usual contain a centralized repository of installed applications, their libraries, and their source /bin contains executables. bin directories appear as subsets of other directories. Notably /usr/bin, /usr/local/bin, and so on. Binaries contained in /bin folders are almost exclusively executables. /bin is the root binary directory and contains all of the systems most key executables. The other bin directories, contain /bin files specific to their location. Installed applications typically have their binaries in /usr/bin. *NIX systems also often include a /sbin directory for system binaries, or scripts, that's essential, but not as essential as /bin /var contains variable files, logs, printer spools, web caches, e-mail caches, information on currently running processes, webserver data, and more. /tmp is for temporary data /home contains all the user space, it's /Users on Macs /home/*. files/directories beginning with a '.' usually represent local user configuration files/directories, and override system defaults. /mnt is an empty directory used for temporary mounts. /dev is one of the most important root folders in that it contains access to the computer's devices. /dev/sda1 for example is the path to the first partition of a SCSI/SATA drive on a typical Linux system. BSDs might be a little different, and might be /dev/wd0s1. BSDs tend to use device names/brands to represent their /dev nodes, where as Linux has evolved to what they call udev, and it provides unique device IDs that are dependent upon the hardware, and UIDs

In addition to this there are other common folders, but they're more dependent on which flavor of *NIX being used.

To navigate with the CLI, the two primary workhorses are:

ls (dir on windows)
cd

ls/dir list the contents of the directory/folder you happend to be in. cd changes the directory. cd .. goes up a folder.

Most versions of ls will support -F. -F adds some visual cues to tell you what files do what. Fancier versions of ls include colourized output that also adds visual cues. -F is more universal. -F will add a * to the end of filenames that can be executed, add an @ to filenames that are links, add a / to filenames that are folders, and possibly more.

With cd/ls you can start finding commands to run. To figure out what a command does, the easiest thing to do is run the command 'man'. man xxxx brings up the manual page for xxxx, which on a good *NIX system will be enough to learn what to do. OpenBSD has the best man pages I've seen in a free OS.

The next most common commands are likely:

mount/umount
grep
find
shutdown
clear
vi
nano
cat
more/less
ps
top
kill
the piping operator '|'
the redirection operators >, >>, /mnt/secret_key.rsa will dump the contents of the file id_public to a new file in the mnt directory. cat /mnt/id_cole.pub >> /home/cole/.ssh/authorized keys would append the contents of the file id_cole.pub to the authorized_keys file in the user cole's home folder under ssh's '.ssh' config folder.

That's pretty much all you need to know to do 80% of CLI stuff. Obviously there's a lot of command specific parameters, especially with more complex servers/daemons.

Here's a few more commands to get into trouble with:

su - trys to authenticate as a super user

sudo xxxxx - where xxx is any command, attempts to run said command as a super user

sed - a low level one pass editor, good for all sorts of weird nerdy things

ifconfig - show info about the network, or configure a network device

ssh - launch a secure shell, this command will let you log into a remote system and use a shell there. SSH supports X11 too, so it can be GUId.

scp - secure copy, copies files to/from systems using ssh

cp - copy files within your system 'cp -r' copies recursive

mv - move/rename files within your system

mkdir - make a folder

rmdir - remove a folder

rm - remove a file 'rm -r' recursively remove

rsync - low level copy 'just what needs updating' possibly one of the most handy programs ever conceived. extrmely useful, operates easily over SSH for secure remote updating/backup.

chown - change ownership of a file

chmod - change file permissions

ctrl-alt-F1-FX, sometimes just ctrl-F1-FX launch alternate terminals. In the context of *NIX GUIs F7 is often X11, or the windowing system, and F1-F5 are traditional non GUI terminals. This feature is less relevant now, as most nerds seem to use several of their preferred X-based applications. Most modern terminal apps support tabs etc, which is quite handy.

There's probably a lot I haven't mentioned, but I think this provides a good foundation for working with a *NIX command line.

This discussion has been archived. No new comments can be posted.

*NIX crash course

Comments Filter:

If you think the system is working, ask someone who's waiting for a prompt.

Working...