Skip to main content

Cracking the linux shell

If you've begun to tinker with your desktop Linux terminal, you may be ready to take a deeper dive.

You're no longer put off by references to "terminal," "command line" or "shell," and you have a grasp of how files are organized. You can distinguish between a command, an option and an argument. You've begun navigating your system.

Now what?

Make It So

File manipulation -- that is, allowing users to traverse the directory structure and interact with its contents -- lies at the heart of Linux. There is a sizable arsenal of tools at your disposal. With the "mkdir" command, you can make new directories. The program takes one argument, which is a path ending with the name of the directory to be created.

$ mkdir new_directory

One nice thing about "mkdir" is that should you specify a directory that already exists, it won't overwrite the original.

Similarly, the "touch" command, taking a path to a file as an argument, can make new (empty) files.

$ touch file

As with "mkdir", "touch" does not harm existing files -- it merely updates the timestamp for its last access. This feature is very useful when making incremental backups, which only save files after a certain date, but "touch" is also great for making disposable files to practice on.

Removing files, using "rm", is a simple task as well, but you should approach it with caution. Supplying a path as an argument for "rm" will remove that file -- but once you hit Enter, it's gone forever. You won't find it in the Trash.

$ rm file

On the one hand, "rm" can't remove directories, so a slip of the keyboard won't cost you dozens of files. On the other, if you do want to remove a directory, and supply the "-r" option, there is no safety net, and the program will delete every directory it contains.

$ rm -r target_directory

If you want to give yourself the same breathing room with directories as "rm" affords regular files, you can use "rmdir", which returns an error and performs no action when the path leads to non-directories.

$ rmdir target_directory

To see file contents directly in terminal output, you can run "cat" with the file given as an argument.

$ cat /file

What's the advantage of using "cat" rather than a paging viewer like "less"? It works faster than "less", and you easily can return the contents of multiple files at once simply by adding more arguments.

$ cat file1 file2

Finally, you can edit files with a terminal text editor like "nano" or "vim". As with any other command, type in the name of your chosen editor with a path to the file and the terminal will bring up the contents in the editor interface. The "nano" editor is a good one to begin with if you're keen to start altering files, as it has usage instructions listed along the bottom.

Shell Basics

To make the most of these new commands in your discovery process, it helps to understand how the shell fits into the picture. Everything your computer runs must be in binary format, so when you type a command, how does the terminal know where the binary is?

The shell maintains an environment variable, a user- or system-wide value associated with a keyword (the variable name), called "PATH," and "PATH" lists all the directories where the shell should look for a command.

Every command, like everything in Linux, has a path, and if you want to know what it is, run the "which" command followed by the name of the command you want to find.

$ which command

You'll get the path right to the binary. Now try running "echo $PATH", which returns the value of the "PATH" variable.

$ echo $PATH

Odds are the directory containing the command you looked up with "which" was in there. This is why you don't have type out the path that "which" returns for every command you run.

There's more to the shell than that, however. To fine-tune its behavior and keep its users organized, the shell -- for Linux, Bash -- maintains a few configuration files. The first is ".bash_profile" or simply ".profile", depending on your Linux distrib

Comments

Popular posts from this blog

What is ARP Monitor?

ARP MONITOR It’s FREE  tool like arpwatch but for Windows OS. This tool can help with ARP activity monitoring in computer networks.   It allows you to catch intruders on the network, track MAC-IP bundles, detect scans, monitor real-time ARP protocol activity in the segment, and much more. This windows software monitors ethernet activity like unix apwatch and keeps a database of ethernet/ip address pairings. new activity - This ethernet/ip address pair has been used for the first time. new station - The ethernet address has not been seen before. flip flop - The ethernet address has changed from the most recently seen address to the second most recently seen address. changed ethernet address - The host switched to a new ethernet address.  Download :   Mirror: http://www.binaryplant.com/binaryplant-arp-monitor.exe

Microsoft showing of its new xbox one dashboard

Microsoft revealed last week that it’s planning to  rebuild the Xbox One dashboard  with a focus on speed. While the software giant revealed common tasks will be faster, Mike Ybarra, head of platform engineering for Xbox, has now teased exactly what the new dashboard will look like. Microsoft is adding a new Xbox button part of the guide that slides into view, with the ability to quickly switch between recent apps or games without having to navigate back to the home of the dashboard. This subtle change could speed up the Xbox One dashboard significantly. One of the big issues of the current guide is heading back to home and watching the entire system slow down and lag, or refresh randomly. The new guide is accessible with a single button press, and it appears the old home concept will be replaced entirely with this quicker method. That should make the Xbox One guide a lot more like the Xbox 360 version, and just easier to use in general.  Windows Central  has captured the brief demo o