Tag: file

By Erick M Aqqa

Unix based operating systems like Linux offer a unique approach to join two discrete commands, and generate a new command using the concept of pipe(lines). For example, consider command1|command2. Here, whatever output is generated by the first command becomes the standard input for the second command. We can develop more and more complex Unix command sequences by joining many commands while maintaining input output relationships.

Another more Linux specific example would be ls -l|grep “^d”. This command displays details of only directories of the current working directory, i.e. the output of the ‘ls -l’ command becomes the input to the grep command, which displays only those lines that start with ‘d’ (they are nothing but the details of the files).

ls -l | grep “^d” | wc -l

This command displays number of directories in the given file.

grep “bash$/ etc / passwd | wc -l

This command displays number of users of the machine whose default shell is bash.

cut -t “: “-f 3 / etc / passwd | sort – n | tail – l

This command displays a number which is the largest used UID number in the system. Here, cut command first extracts UID’s of all the users in the system from the /etc / passwd file, and the same becomes input to sort; which sorts these numbers in numerical order and sends to tail command as input which in turn displays the largest number (last one).

tee command

The ‘tee’ command is used to save intermediate results in a piping sequence. It accepts a set of filenames as arguments and sends its standard input to all these files while giving the same as standard output. Thus, use of this in piping sequence will not break up the pipe.

For example, if you want to save the details of the directories of the current working directory while knowing their using the above piping sequence we can use tee as follows. Here, the file xyz will have the details of the directories stored.

ls -l | grep “^d” |tee xyz | wc -l

The following piping sequence writes the number of directories into the file pqr while displaying the name on the screen.

ls -l | grep “^d” | tee xyz | wc -l |tee pqr

cmp command

The cmp utility compares two files of any type and writes the results to the standard output. By default, cmp is silent if the files are the same. If they differ, the byte and line number at which the first difference occurred is reported.

Bytes and lines are numbered beginning with one.

For example, cmp file1 file2

comm command

comm is a command used to compare two sorted files line by line.

Compare sorted files LEFT_FILE and RIGHT_FILE line by line.

-1 suppresses lines that are unique to the left file.

-2 suppress files that are unique to the right file.

-3 suppress lines that appear in both the left file and the right file. For example, comm p1 p2.

A pipe thus helps connect a set of processes, so that the output of one becomes the input of another. It lets a user browse through a large amount of data in a convenient manner.

Linux2Aix is an upbeat Linux blog containing all the latest and the newest Linus news and how-to’s for both amateur and professional Linux lovers

Tags: , , , , , , , , , , , , ,

Best Beginners Linux Commands

By Dennis Frank Parker

There are many common Linux commands that will be to your benefit, if you ever even use your command line software in Linux. Many average users just use the graphical user interface instead which usually provides many tools and front-ends to Linux common commands. This Linux system tutorial on control commands will help the average user in the event X server accidents, fails, is not properly designed, etc. So stay with me for some of the more prevalent Linux bash instructions.

Some of the more Best free Linux tutorials. A Linux system Unix shell commands tend to be listed below for more information on each command you can always manage man [command] and this will bring up the manage for that command, you can also click on the requires listed for some frequent examples and format.

First before I list them virtually any syntax in [] will be needing some kind of input of your stuff normally, for example:

guy [command] you will want to actually change [command] with the shell order you want to read the guy page for: gentleman ls will give you the man page for the Linux covering command ls.

    • linux ls command – is used to list files on the filesystem.


    • File – command that will check the filetype, this will output to you what the file type is no matter what the extension is.


    • Mkdir command – used to make directories on the filesystem.


    • cd- is used for changing into a different directory in the Linux shell


    • cp – is the Linux copy command, this shell command is used to copy files|directories from one location on the filesystem to another.


    • Mv – the Linux terminal command to move files|directories. Like the cp command, but deletes the original source.


    • rm- shell command in Linux to remove files|directories.


    • Linux cat command- this command is used to print|view the contents of a file to the screen|terminal.


    • Grep – command used to search|find contents of a file and print|view on your terminal|screen.


    • Linux more and less – commands that will allow you to read output of files, unlike cat that will output the entire file at once, even if it is too large for your terminal more and less will output only as many lines as the shell you are in can output, and allow you to scroll through the file contents.


    • Chown – Linux command to change ownership of a file|directory.


    • Linux chmod – command that allows you to change mode of user access|permissions, basically set read, write, and execute permissions.


    • Linux ps – lists the current running processes on your Linux system


  • Linux kill and killall commands – used to kill|terminate running processes

We Provide Best free Linux tutorials and Cbt nuggets training.

Tags: , , , , , , , , , , , , , , ,

Understanding the Linux File System
By Brandon Sherwood

The way Linux organizes its files on the hard drive is vastly different from how Windows handles this task. New Linux users coming from Windows sometime have a hard time maneuvering though directories or come with notions that Linux should manage its files in the same vain as Windows.

This article was written to help new users get a grasp on moving through directories on their new installation. One key point to make is Windows deals with “drives” as in your C: drive or D: drive, Linux deals with something called ‘mount points’. These are locations where other hard drives, CD/DVD burners, etc… connect to the root partition. Don’t worry it will all make sense latter on.

It All Begins With Root: /

The root directory known simply as ‘/’ is the starting point. Without getting to technical, the root directory acts like the ‘C: Drive’ in Windows. A Linux system can not fully boot without a root partition, in the same way as deleting your C:WINDOWS folder will make your Windows computer inoperable.

It’s In: /bin

The /bin folder holds important system programs. The ‘bin’ is short for ‘binary’. Some of the popular programs: date, less, more, cat, dmesg. These programs are essential in order to start and have a complete operating system. While you may never use one of these programs personally, the system relies on some of them.

Where Everything Starts: /boot

As the name implies, /boot is where the crucial files reside, mainly the kernel. Without the kernel, you don’t have a system. Another crucial program located in /boot is the bootloader. Just like Linux needs the kernel to function. The bootloader is there to actually locate the kernel and begin running it.

Every Device Is A File: /dev

In Linux, every device is a file. What this means is, when you connect a hard drive to your system it gets a ‘device file’ that allows the system to interact with it. When the kernel locates a new hard drive it is assigned a file like “/dev/sda”. The /dev part is the directory and the ‘sda’ part is the file that connects to the hardware. So if you wanted to format your whole drive you could type in the command ‘dd if=/dev/null of=/dev/sda’. This would copy /dev/null into your hard drive. /dev/null is a “bit bucket”. Meaning that everything that gets sent to it gets deleted.

Configuration-ness: /etc

Linux, being a customizable system keeps all the programs config’ files in this directory. Most programs come with a sensible and secure default behavior. But what happens if you want to change it? The /etc holds a slew of text files for you to open and customize how your programs operate. An important note to make is /etc manages global defaults. What this means is if you change a file this directory, it will affect the whole system.

The Shared Libraries: /lib

The /lib directory is a way to keep all software libraries in one central location. Most (if not all) files here have a file extension of ‘.so’ to let you know they are ‘shared object’ files. These files are code that can be used by multiple programs. This helps prevent a problem known as ‘software bloat’. Windows also has these files; they are called ‘Dynamically Linked Libraries’ or DLL for short. As a regular Linux end user, you will most likely never have to change anything in this folder. Depending on how you install software on your computer, you might come across a ‘missing shared object’ problem if your software “depends” on another program to function. The Windows equivalent is ‘DLL hell’.

When You Don’t Shut Down Correctly: /lost+found

This directory is used when the user does not shut down the system correctly (turning it off when the system is still up and running). Upon the next boot, the system will try and correct itself by scanning the hard drive for corrupt files and try to correct any problems that arise. If anything is found, it will be placed in the /lost+found directory for the systems administrator (you!) to see and look over.

Where The ‘Mount Points’ Live: /mnt and /media

The /mnt and /media directories are for ‘attaching’ other devices to the root directory. In Windows, when you insert a USB thumbstick, you will see the system gives it a drive letter (E:). Depending on which Linux distribution you use, the device will either ‘auto mount’ or the user has to mount the device manually. Most newer, newbie friendly distros will auto mount the device and place it in one of these directories. You will be able to browse the files within your thumbstick at /mnt/usb or /media/usb. Each distribution is different, so my example could not exactly match your results.

/media is the newcomer to the Linux scene. Most older distributions exclusively used /mnt to manage these devices, but /media is gaining ground as the default location to mount devices. Linux allows you to mount any device anywhere (as long as you have the permissions). So it is completely feasible to mount one device under ‘/bin/mount’ or ‘/var/log’. This is usually not a good idea and the /mnt and /media directories where put in place to make this easier.

The ‘Optional’ Directory: /opt

This is where users can install software if no other suitable location can be used. Most software from major Linux distributions have ‘software repositories’ which allow users to easily add and remove tons of programs. But what happens when you need a program that isn’t in the repository? In order to separate repository software packages from ‘external’ packages, sometimes the best way to install them is putting them in /opt. This practice is rarely used though and each distribution is different. Some will place the popular KDE into /opt, while other distributions won’t.

My personal rule of thumb is to use /opt when the software you are installing defaults to this directory (The Google Earth program does this) or I am installing a program that I didn’t get in the software repository.

The Kernel’s Directory:/proc and /sys

Both of these directories hold a wealth of information about the status of your system. Files like ‘/proc/cpuinfo’ contain information about your CPU (speed, vendor, cache size). The /proc directory is slowly being faded out in favor of /sys.

You Were Here And Now Your Gone: /tmp

The /tmp directory is short for ‘temporary’. So with that in mind, I am sure you can deduce why this directory is used. You got it, to manage temporary files. Programs can generate a lot of ‘junk output’ or need to write to a file to handle a task; but the file can be deleted once the task is completed. This directory provides a central location to do this and not fill your other directories with these files.

Where The Programs Live: /usr

The /usr directory is a monster. Articles could be written just to explain it all. But to keep things short and sweet, the /usr is where all of your ‘secondary’ programs are stored. Granted you love your music player, but it’s not crucial to your operating system actually functioning. So instead of putting all the executables in /bin, we break it up a bit. We place crucial system programs in /bin and non-critical programs into /usr/bin. The /usr directory could be seen as the Windows equivalent as C:Program Files .

The Not So Temporary Files: /var

/var (for varying or variable) acts like /tmp in the sense that the files located are ‘temporary’ but less ‘temporary’ then those in /tmp. What this really means is the /tmp directory will most likely be deleted every time the system reboots, while the files in /var will not. /var is a place to keep ‘persistent’ files. An example would be log files. Most system administrators wouldn’t want to delete their log files on every reboot, but the files could be removed or ‘shrunk’ to a more manageable level at the administrators whim.

Another example would be ‘/var/mail’ directory. It contains the mail being sent to users on the system. Some users will have hundreds of messages, while other users will have a few or none. The directory is growing and shrinking depending on the usage by the users. So in order to keep the disk usage under manageable levels, we place this activity under /var. On large systems, the system administrator will use a separate hard drive and ‘mount’ the hard drive at /var. This allows the frequent disk access to remain on one hard drive and keep the overall system speedy.


Well I hoped that this article has better acquainted you to how files are stored on a Linux system. If I left anything out (or for general praise), please feel free to comment on the article.

Brandon Sherwood

http://www.newbtopro.com – Howto’s and Tutorials

Tags: , , , ,
Back to top