Tag: ls

gnuBy Rand Whitehall

In the Linux command line shell, moving around from directory to directory, adding new directories, and deleting old directories is easy once you know the proper commands. Again, with Linux, you are limited only by your brain! If you know all the commands, then you weild great power. But if you know only a few commands, it’s like you are standing in the airport in Tokyo and want to know where the bathroom is, but only know how to say hi and bye in Japanese.

Let’s get to it. Open a shell (or terminal) and type each line below followed by enter:

cd

pwd

You should be in your home directory, which is the same name as your username. So if your username is barney22, your home directory should be /home/barney22.

Now, let’s create a new directory to play with. (Remember, when learning the command line in Linux, always play with new directories and files you create to practice with. Never practice with important files and directories.) Type this:

mkdir doggy [enter]

ls [enter]

Now you should see your new directory called doggy in the ls output. Great! Now what? Let’s change the name. Type:

mv doggy doggyDo [enter]

ls [enter]

And you should see the directory name has been changed from doggy to doggyDo. Great! Hmmm… Now let’s go into the doggyDo directory and create a text file.

cd doggyDo [enter]

touch shibaken.txt [enter]

ls [enter]

Now, you should be in your doggyDo directory and see the new text file you created with the touch command. If for some reason you got lost somewhere along the line, go “home” by typing this:

cd [enter]

A cd command with no destination will take you home every time.

Now, let’s say you want to move the doggyDo directory into another directory. Let’s create another directory first, like this:

cd [enter]

mkdir doggyDocs [enter]

Now let’s move the doggyDo directory into the doggyDocs directory like this:

mv doggyDo doggyDocs [enter]

ls [enter]

You should see the doggyDocs directory now, but not the doggyDo directory because it is inside doggyDocs.

cd doggyDocs [enter]

ls [enter]

You should see your doggyDo directory there inside doggyDocs.

I hope you learned a lot about creating and moving directories around in the Linux command line. If this was a bit confusing, then just go through it again slowly. With a little practice your fingers will know what to do as soon as you think of it!

Rand writes about web design, Linux, men’s health and more. Please check out his DE safety razor site for shaving info and tips and the latest on the Merkur Futur safety razor. It’s a great resource for those who are passionate about a quality, close shave.

Tags: , , , , , ,

By Christopher P Wakefield

This time we are going to have a look at Linux permissions. Every current operating system deals with permissions, whether it is ownership of a file or just gaining read access to a folder. As with everything else in Linux there are command line tools and the graphical user interface so we shall discuss both.

chown --helpThe Chown Utility

This is a command line tool that deals with the ownership of a file or folder. Open up a terminal and switch to root. Navigate to the directory which contains the file / folder you want to change and type:

chown [username][file /folder]

So for example if I wanted to change the owner of a file called tools to natasha and it was located in /home/chris I would type:

cd /home/chris

chown natasha tools

To check who owns a particular file / folder you can navigate to the directory that contains the file / folder and type:

ls -l

The Chmod Utility

Next up is the chmod utility which deals with permissions themselves. Open up a terminal and switch to root. Navigate to the directory which contains the file / folder you want to change and type:

chmod [777][file / folder]

Lets first explain the numbering system above. There are three types of permissions in Linux – Read, Write and Execute which are given values of 4, 2 and 1 respectively. So in the syntax above the file would be given Read (4), Write (2) and Execute (1) permissions (4+2+1 = 7). But don’t you give permissions to people and not files or folders? Correct, that is why there are three numbers which represent the owner, group and others. Lets take an example to illustrate the point. Say I wanted to change the permissions of a file called tools.doc to owner (rwe), group (rw) and others (r) and it was located in /home/chris I would type:

cd /home/chris

chmod 764 tools.doc

This gives the owner (rwe = 7) group (rw = 6) and others (r=4) different levels of access to the file.

Graphical Means of Changing Permissions and Ownership

For people who don’t want to use the command line there is another way to do all this. I shall illustrate this using Linux Mint 9. Locate the file you want to alter by using your file manager. Right click and go to open as root. In Linux Mint 9 the background will go red when a file is open as root. Right click and go to properties. On the properties page you will be given the option of changing permissions for the owner, group and others along with changing the owner of the file. Change accordingly.

Hi I am Chris the owner of ComTech. I provide IT support to both personal and business clients from my base in Alloa, Clacknmannanshire. Here at ComTech I am experienced in using Windows, Linux and Cisco technologies whether it be for the home or business. I also incorporate Blackberry hardware into my business, namely the Blackberry Playbook and Bold 9780. I can advise, design and implement solutions to any problems you may have so if you have IT issues just pick up the phone. Please go to http://www.comtech247.net for more information.

Tags: , , , , ,

By Rand Whitehall

If you are just starting out using the command line in Linux, knowing just a few key commands can take you a long way towards fluency in the cli (command line interface) environment. Most new linux users fear the dreaded command line and its archane text-based commands. But if you warm up to the command line slowly and patiently, you’ll start to see you can wield great power over your computer using cli tools. It is truly amazing how much you can do with the cli and how quickly and efficiently it can do things. Some tasks can be done with a few lines of commands in under a second that would take thousands of mouse clicks and hours to accomplish in a typical GUI (graphical user interface).

The ls command is very powerful and useful so we’ll start there, then take a look at the file command.

ls: The ls command lists the contents of a directory. Simply type ls and hit the enter key. You should see a list of the contents of your current directory.

Now, if you want to get a bit fancy, you can tell ls to show you file sizes as well by adding the -l switch like this: ls -l.

This will show you the contents of the directory and files size, file date, file time and file name.

Now, while you are looking at details of the files in your current directory, you may be wondering what type of files they are. For example, if my home directory had a file called joe, I would type file joe to find out what type of file it was.

The file named joe is a text file so the file command outputs: joe.txt UTF-8 Unicode English text.

I’ve also got a directory listed called bob. If I type file: bob, then file outputs: bob/ directory.

The file command can tell us about any type of file. Digging deeper into my filesystem I come across a file that I don’t know. What type of file is it? Run the file command. file: bak.sh. The output of the file command: Bourne-Again shell script text executable. Ahh, it’s a bash script.

What’s a bash script? It’s a list of cli commands strung together in a text file. A bash script is like a small program that can perform just about any number of tasks. Very powerful stuff once you get a few more commands under your belt.

Rand writes about Linux, old school safety razors and blue nitrile gloves! Check out Rand’s site all about latex free nitrile gloves, a great barrier against infection. Black Nitrile Gloves are also available and used often by tattoo artists, mechanics and industries where keeping dirt and grime free is important.

Tags: , , , , ,

Important Unix Commands That You Should Know

By Bernard Peh

Unix is one of the most important operating system today. Its powerful features, scalability, strong security, and support for multiple users have made it the top choice operating systems for server, workstations and mainframes.

It is good to have some knowledge of Unix commands especially if your web host is Unix/Linux based. You could do alot of things by yourself by logging into the server via Secure Shell(SSH). This article will describe some of the important “need to know” Unix commands.

1. ls

This command will show you what files are in your current directory. If you add in a -F option, ie “ls -F xxx”, there will be a “/” appended to the end of directory names, * to executables and @ to links. “ls -a xxx” will display all hidden files as well. This is also the most used command.

2. cd

Change directory. If you type “cd xx”, it means to change to the specified directory “xx”. “cd ~” means to change to your default home directory.

3. cp “a b”

Copy file a to b. If b is a directory, the new file will be named b/a.

4. mv “a b”

Move files from a to b. For example, if I type “mv songs.txt /tmp”, the file songs.txt will be moved to /tmp/songs.txt. Moving a file is the same as renaming a file.

5. echo “text”

Print “text” to the terminal. If “text” is surrounded by double quotes, the text will be printed with any environment variables such as $HOME. If “text” is surrounded by single quotes, the “text” is printed without any special processing.

6. pwd

Print the current working directory. Useful command when you are lost in the directories.

7. cat “file”

Print the contents of the specified file(s) to the terminal.

8. less “file”

Display the specified file one screen at a time. Press the spacebar to go to the next screen. Press Q to quit. You often combine “less” with some other commands such as “cat abc | less”. This command means you print the contents of the file abc and display it one page at a time.

9. ps

Display information about your running programs. This is a good command to use if your server is slow and you suspect that some applications are taking too much memory. The most famous command using ps is “ps aux”. This will display useful information on the running programs.

10. rm

Remove or delete a file. If you type “rm -r directory”, it will remove a directory and all the files underneath it recursively.

11. man

This is the most important command. man means “manual”. If you are stuck with cat command for example, type “man cat” and you can see the help file.

Bernard Peh is a great passioner of web technologies and one of the co-founders of SiteCritic Website Reviews. He works with experienced web designers and developers for more than 5 years, developing and designing commercial and non-commercial websites. During his free time, he does website reviews,freelance SEO and PHP work.

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

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: , , , , , , , , , , , , , , ,

Using the Linux Ls Command to See Linux File “Patterns” – Linux Commands Training Quick Tips

By Clyde E. Boom

The [pattern] Part of a Linux Command

The Linux [pattern] (a.k.a. Linux shell pattern) part of a Linux command is a combination of letters and wildcard characters that are used with Linux commands to view information about Linux directories and files.

The Linux [pattern] of a Linux command does not work the same with all commands.

Linux ls Command Examples Showing Linux Command Patterns for Linux Files and Directories

The Linux commands examples that are shown below will help you to understand how a “file (or directory) matching pattern” can be used with a Linux command.

The Linux commands below will work in most Linux distributions, however, some of the Linux ls commands below may not show any Linux files in the output, depending on your Linux distribution.

The [pattern] component of a command is used to represent a file matching “pattern”. It can be one or more letters, numbers or other characters and may include the * (asterisk) and ? (question mark) wildcard characters.

A [pattern] can be the name of an item (directory or file) or part of the name of an item (plus wildcard characters).

A [path] to a directory can precede a [pattern] (as shown in the second Linux command example shown below).

When a [path] is not used with a command, the command will typically display output based on the files in the current directory (as shown in the first Linux command example below).

The Linux ls command below uses the pattern of * (a single asterisk) to show all files in the current directory (and if you’re working as a “regular” user and you’re in your home directory, there may not be any files or directories that appear).

$ ls -l *

The ls command below uses the path and pattern of “/etc/hos*” to show all files in the etc directory that begin with “hos”. The [path] is /etc and the [pattern] is “hos*” (which uses the * wildcard character in the pattern).

$ ls -l /etc/host*

The suffix (a.k.a. filename extension, extension) in the name of an item is the far right . (dot) and characters at the right of the . (dot).

For example, in the directory named rc.d, the “.d” is the suffix of the directory and in the file named speedbar.gz, the “.gz” is the suffix of the file.

In the Linux ls command example below, the path and pattern is “/etc/*.cfg” and path is “/etc” and the pattern is “*.cfg”. This Linux command shows a listing of all files that end in “.cfg” in the etc directory, which is below the root directory.

$ ls -l /etc/*.cfg

In the ls command example below, the ? wildcard character is used to represent any single character in the pattern of “host?” to show only files with a single character at the right of “host”.

$ ls -l /etc/host?

The Linux concepts and commands discussed above apply to Red Hat, Debian, Slackware, Ubuntu, Fedora, SUSE and openSUSE Linux – and also ALL Linux distributions.

And now I would like to offer you free access to my Linux Commands Training Mini-Course, a 7 Lesson, Daily Mini-Course, including the free Linux Commands ebook and Linux audio podcasts – showing you how to get started learning how to use Linux commands.

You can get your instant access at: http://www.LinuxCommandsTrainingCourse.com

From Clyde Boom – The Easy Linux Training Guy – Easy, self-paced Linux training – In Plain English!

Tags: ,

An Introduction to Linux Shell Commands

By Erick M Aqqa

The Linux system often intimidates beginners, what with the need to type in a command or two every now and then. However, Linux commands (or shell commands, to put it more accurately) follow a rather logical and sensible pattern and all you need to do is get used to it! Most shell commands are roughly 3, or at most 4 letters long. The more frequently needed commands are shortened further usually.

The man command is a reference to ‘manual’, i.e. the documentation that comes preloaded in Linux systems to help you with common problems faced by a user. These man(ual) pages are certainly not meant to be standalone guides for beginners, but instead, they need to be used as reference material to corroborate what you’ve learnt/tried elsewhere.

The info command is another way to look up reference material for GNU information and troubleshooting suggestions. It isn’t completely the same as the man pages, as there is a scope for using ‘hyperlinks’, to make it easier to browse through the material you need. There are shortcuts for scrolling through pages too.

The date command is self-explanatory. It will tell you about the current time and date on the system. On those lines, the cal command will display a neat calendar of the current month (or that of any particular one you choose).

The ls command is meant to help you list the contents of the directory you choose. This means that you will get to see all the files and directories inside your current directory.This command also has switches to modify its behavior and functionality. For example, adding -l after ls will give you a more detailed description of the contents of the directory you’re in. you’ll get to see details about file permissions, modification dates, groups, sizes and owners. The -a switch helps you see all the files in your current directory, including the hidden ones. (Hidden files in Linux have their filenames starting with a ‘.’ i.e. a period)

In case you lose track of the current directory you are in, type pwd, which prints the current directory you are working in. Once you’ve got to know that, you can navigate around the Linux file system using the cd command, where ‘cd’ stands for ‘change directory’. This can work on both relative and absolute terms, i.e., you can work by specifying the entire directory, starting from ‘/’ (the home directory) to the directory/file you want to go to. Otherwise, you can also use the ‘.’ or ‘..’ system. The latter tells the compiler that you want to go to the parent directory of your current one, making it an easy alternative to typing the entire path every time.

When you start working with simple files, like text files, the cat command will come in handy. It ‘concatenates’ the content of one or more text files, letting you see all of the text they contain.

The ps command lists all the processes currently running on your system in your current terminal.

The shell commands in this article are a good way to start off in the Linux environment. They are simple enough for you to get an idea of how the entire system works, and will probably help you to try out more advanced steps later!

To know more about Linux shell commands, click here

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: , , , , , , ,

Linux Usr System Directory – Ls (List Directory) Command Examples – Quick Tips

By Clyde E. Boom

The Linux usr Directory

The usr directory, below the /, typically contains application software programs and utilities that can be shared across a network. It is the parent directory for many system components, including documentation files.

This directory is the “parent” for the share directory, which is the parent for doc, man and info.

These three directories contain documentation regarding Linux OS components and provide an excellent example of a well-organized directory structure.

You will see this illustrated for the “man” directories in the command examples below.

List the directories in the root and notice that the usr directory is “below” the /.

$ ls /

Now view the items in this directory.

$ ls /usr

Notice the doc, info and man directories.

Change into the share directory, below the path of /usr and list the contents.

Linux Commands Training Tips: You can use a ; (semicolon) with a space on either side, to run more than one Linux command on the same line.

$ cd /usr/share ; ls

Now use the Linux file “pattern” of “m*” to list only items beginning with “m”.

$ ls m*

This shows all items that begin with “m” and also shows the items (mostly files) in the directories beginning with “m”.

You can click on the top right arrow in your terminal emulation window to scroll up and see all of the output.

Directory names are flush left and on a single line and end in a : (colon).

Now use the -d option to show the directories only – and not the contents of the ones beginning with “m”.

$ ls -d m*

Now add the -l option to get a long listing.

$ ls -ld m*

Notice the directory named “man“. This is the parent directory of the Linux man pages, which are files providing documentation on system software components, including Linux commands.

The man command is used to view the contents of manual pages and can be run from any directory and as any Linux user.

$ man ls

This shows the man page for the ls command, which has a very brief description of the command and shows all of its options (preceded by a dash).

Press q to quit out of the man page.

Linux Commands Training Tips: Unfortunately, Linux man pages rarely show examples of how to use a command!

Now change into the man directory and view its contents.

$ clear ; cd man ; ls -ld man*

Each directory below contains files for a category of documentation.

The following command example uses the pattern of “ls.* to show the man page file in the man1 subdirectory that contains the description of the ls command that you saw above.

$ ls -l man1/ls.*

The Linux usr directory and command examples shown here apply to ALL Linux distributions, including Ubuntu, Kubuntu, Debian, SUSE, openSUSE, Fedora, Red Hat and Slackware Linux.

And now I would like to offer you free access to my Linux Commands Training Mini-Course, a 7 Lesson, Daily Mini-Course, including the free Linux Commands ebook and Linux audio podcasts – showing you how to get started learning how to use Linux commands.

You can get your instant access at: http://www.LinuxCommandsTrainingCourse.com

From Clyde Boom – The Easy Linux Training Guy – Easy, self-paced Linux training – In Plain English!

Tags: , , ,
Back to top