Tag: grep

By Clyde E. Boom

When you are a new user and trying to get Linux training, you need to learn how to use commands.

What you most often need is a clear, detailed example showing you exactly how to use a command.

And you’ll often hear seasoned Linux users say (over and over again) “just see the man page” for a command. This has become a quick and easy way out of really trying to explain how to use the command.

Linux man pages are useful if you already know how to use a command, but extremely frustrating if you are new to the OS (operating system).

Linux Training Tips: Linux man pages are practically useless for someone new. In fact, they’re almost as easy as trying to read hieroglyphics. Great for the ancient Egyptians – lots of really nice pictures, but really hard to read.

Here’s Why Man Pages Don’t Work for Someone New to Linux – And What You Can Do About It

linux man command“Man” stands for “manual”, as in “software documentation and you run the Linux man command to display the contents of a help page (file).

So, if you need help on a Linux command (or software program), you just run the man command to get instant online help.

Sounds great – but it’s not great for a new user.

And it would be great if the people that knew how to use Linux, didn’t expect the people that are new to understand man pages!

Linux Training Tips: The Linux System Administration concepts, commands and tasks covered here apply to ALL other Linux distributions, including: Red Hat, Fedora, Ubuntu, Kubuntu, Edubuntu, Slackware, Debian, SUSE and openSUSE.

Here’s how to run the Linux man command and get help on the grep command:

$ man grep

This displays the contents of the help page (file) for the grep command.

Linux Training Tips: There are several options of this command that can be used to display information on multiple pages. But hey, how do I get help on this command? You guessed it – just run: man man

Now, the grep command is pretty amazing in what it can do. It has lots of options and different ways of getting tons of useful information from a Linux system – but you’d never know it from looking at the man page.

The man page for any Linux command just shows you: a vague description of the command, a cryptic statement showing how to run the command, and a long alphabetic listing of the options. There’s no way of knowing which options are the most useful and most commonly used.

And the worst part is that it’s almost impossible to find an example of a command.

In the thousands of man pages, there are almost never any examples of how to use a command. And seeing examples of a command (and then running the command) – is the best way to learn how to use Linux.

Instead of trying to decipher a cryptic man page, imagine watching a clearly narrated Linux training videos. Easy training at it’s best!

With this Linux training method you get to see and hear how to use a command – or learn a new concept.

You see every step in the process – and whenever you need to think about something, or want to try a command you’ve just seen, you just click pause and try it yourself!

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

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

GNU-Linux Tools – Regular Expressions Basics

By Rand Whitehall

A regular expression, (also known as regexp or regex) helps us match a string of text. They can also match specific words, groups of words or characters.

Now, by themselves, regexps don’t do much. But combined with Linux search tools, they are very powerful. Here we’ll use the grep tool with regexps.

Now let’s take a look at an example. Say you wanted to find all the lines in a text file that started with the word “Joe” in a text file called bob.txt. You really can’t do this kind of thing with a typical GUI search tool. But with grep and regexp, it’s easy. Well, easy once you get the hang of it!

Our file bob.txt contains six lines:

Bob is a great guy

Unlike his buddy, Joe.

Bob likes to work.

Joe is a real bum.

Joe likes to watch other people work.

Jim is my hero.

James is not.

Here’s the grep command:

grep ‘^Joe ‘* bob.txt

Output:

Joe is a real bum.

Joe likes to watch other people work.

Notice how only the lines that start with Joe are printed?

The ‘^Joe’* part is the regular expression.

The ^ means start at the beginning of the line.

“Joe” means search for the word Joe.

The * is a wildcard meaning anything can come after Joe.

What if we wanted to match all lines in which the second letter is “o”?

In this case we need to use the. (period), which tells grep to search for any single character.

grep ‘^.o’ bob.txt

Output:

Bob is a great guy.

Bob likes to work.

Joe is a real bum.

Joe likes to watch other people work.

The [] brackets, are used to match a range of characters. For example, we could search for any lines that start with a “J” then any letter between a-m.

grep ‘^J[a-m]‘ bob.txt

Output:

Jim is my hero.

James is not.

Now, even though Jim starts with a “J”, it is excluded because the second character is not between a-m.

I hope this gets you more familiar using regexps. Please be aware that there are several versions of grep and some use slightly different regexp expressions. If you find a great regexp on the internet and it doesn’t work on your system, it may be because it’s not compatible with your particular version of grep. We’ve only touched the surface here, but I hope this gives some understanding of regexps and a hint at how powerful they can be.

Rand’s Adjustable Safety Razor website is a fantastic resource for old-school double-edge razor fans. Check out the Merkur safety razor page for info on Merkur’s adjustable safety razors.

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

Linux – Find Files Containing Text

By Selwin Verallo

Because of our being forgetful in nature, we oftentimes forget the files that we have created. We can only be fortunate if we can still remember the path, folder, or directory where we have stored those missing files. If that’s the case, it would never be a big deal then. However, trully this a big problem and even painful if we can’t even remember where we have placed the missing files in our computer. “Simple,” I’m hearing you… “find it.” Yeah, we can find it. But wait, do you know the filename?

Forgetting files and forgetting the filenames are most common in us. I will never believe somebody out there have a photographic memory and has never experienced missing some of the files he had created before. For sure, we all have gone through that frightening experience especially if the file that is missing is so precious to us.

In Windows, this problem can easily be addressed just by using the find or search tool in the Start menu. Can you remember some texts or phrases in the filename? Use “find files with names” and unleash the power of the wildcard character (*). For example, if you can only remember the word “statistic” in the filename, then search for “*statistic*” and that will search for files with the word “statistic” in the filename. “I can’t even remember a word in the filename,” again I can hear you saying that. Well, I don’t think you can’t even remeber even a single word in the file content itself. If you can’t remember even a word or phrase in the filename then go for the file content itself. In Windows, still you can search for files containing some texts that you specify in your “find files containing text” input box. That will absolutely solve your problem of forgetting words in the filename itself.

However, if you are in Linux, the whole thing would be more different and complex than it is in Windows especially if you are just a normal user dependent on the GUI interface. Linux is more on executing commands from a shell.

So if you are a normal user and that you are facing the “missing files” problem in Linux, don’t worry, I will show you the most common methods in solving this issue:

Find files that contain a text string

grep -lir “text to find” *

The -l switch outputs only the names of files in which the text occurs (instead of each line containing the text), the -i switch ignores the case, and the -r descends into subdirectories.

Find files containing search terms on Ubuntu

To find files containing keywords, linux has a powerful command called grep, which you can use to find the lines inside any file or a list of files.

grep -i -n ‘text to search’ *

List files containing text

Used to recursively search a directory for files containing a string, output the names of the files and the line number. This will search all regular files in for.

grep –with-filename –line-number `find -type f`

Find more tips and techniques at Smart Pad

Tags: , , , ,
Back to top