Archive for the ‘Basics’ Category.

Basics of User Management

tux.png

A comprehensive guide for basic user management of a linux box:
Continue reading ‘Basics of User Management’ »

An overview of the find command

terminal.png

Let us see how to use find command to  gain lots of useful information about users and their files.

Continue reading ‘An overview of the find command’ »

The most common usage of sed

terminal.png

make a file with your favorite text editor. Name this file “old” and place the word “day” within it. Save it in your home directory. /home/<username>.

Now in a shell run:

sed s/day/night/ old >new

Now you will have a file called “new”. Open that file and it should have changed the word day to night.

Re-edit the file “old” and make it look like this:

day day day

day

day

Save the file.

This time we’ll run a similar command

sed s/day/night/ old>new.2

When viewing the file new.2 you will see this:

night day day day

night

night

You will notice only the first field in each line got changed. Most Unix utilties work on files, reading a line at a time. Sed, by default, is the same way. If you tell it to change a word, it will only change the first occurrence of the word on a line. You may want to make the change on every word on the line instead of the first.

sed s/day/night/g old>new.3

Now if you view the new.3 file, every instance of day should have turned to night:

$ cat new.3

night night night night

night

night

The ‘g’ option tells sed to run globally and not for the first instance within each line.

This is my very over simplified take on sed. Please see the link above and the sed man page for more. Feel free to talk about it

For a more advanced look at Sed please see here: http://www.grymoire.com/Unix/Sed.html

Deleting old files in Linux with find

terminal.png

While the Linux find command has a number of uses, the most obvious being looking for files matching full or partial names, the one often underused option is to use it to locate old files. To show all files in a directory older than 14  days:

find /var/crap_files/* -mtime +14 -print

An even more powerful option is to use the -exec switch which allows you to delete old files. To delete all files in /var/crap_files/ older than 7 days:

find /var/crap_files/* -mtime +14 -exec /bin/rm -rf {} \; 2>/dev/null 1>&2

Linux: Rute User’s Tutorial and Exposition

tux.png

Recently added to the site: Linux: Rute User’s Tutorial and Exposition (you’ll notice another link to it on the right hand column beneath the sections).

This is a great Linux reference covering a great deal of the basics, available for legal electronic distribution.  Enjoy.

An introduction to sed

terminal.png
  • sed reads from a file or from its standard input, and outputs to its standard output. You will generally want to redirect that into a file, but that is not done in these examples just because it takes up space. sed does not get along with non-text files, like executables and FrameMaker files. If you need to edit those, use a binary editor like hexl-mode in emacs.
  • The most frustrating thing about trying to learn sed is getting your program past the shell’s parser. The proper way is to use single quotes around the program, like so:>sed ’s/fubar/foobar/’ filenameThe single quotes protect almost everything from the shell. In csh or tcsh, you still have to watch out for exclamation marks, but other than that, you’re safe.
  • The second most frustrating thing about trying to learn sed is the lovely error messages:
    	sed 's/fubar/foobar' filename
    	sed: command garbled: s/fubar/foobar
  • The GNU version of sed generally has better error messages:
    	gsed 's/fubar/foobar' filename
    	gsed: Unterminated `s' command

    So, if you’re having problems getting sed syntax correct, switch to gsed for a while.

Continue reading ‘An introduction to sed’ »

Getting Familiar with Linux Logs

terminal.png

In almost all Linux distributions the Linux log files are stored in ‘/var/log‘ directory.

A common way to watch log files is to use the -f flag and tail. Most log files are protected so you will need elevated privileges to view them.

Show the last few logins and display new ones as they are authenticated. Ctrl + C to quit.

Continue reading ‘Getting Familiar with Linux Logs’ »

How to stop cron from mailing you

terminal.png

Running numerous jobs via the cron daemon on a daily, even hourly, basis can lead to a lot of mail notifications. I run many jobs whose output I do not really need to be informed of (for example, the overnight stats run on some of my web servers; I am in the habit of checking stats daily and if the job failed I would know), so how do I go about preventing crond telling me about these jobs?

Continue reading ‘How to stop cron from mailing you’ »

How PAM works

tux.png

PAM (Pluggable Authentication Modules) is one of those dark corners of Linux where most users don’t venture – in fact, I’d be willing to bet that the majority of Linux users don’t even know what it is. And yet, PAM is at the heart of every single thing in Linux to do with authentication.

Take our guided tour of PAM, join our science lab and perform our experiments (no bunsen burner necessary!) and see how PAM gives you fine-grain control over your security policy.

Continue reading ‘How PAM works’ »

How to prevent Linux from remembering your sudo password

terminal.png

You may know that if you type

sudo [command]

Your password will be asked, but if you type it again in a few seconds, it will not be asked, because Linux “remember” your password for some time, well if you are really concerned about this, you may force Linux to “forget” your password inmediately.

How to do it?

sudo visudo

And add this line:

Defaults	timestamp_timeout = 0

You may change 0 to any number representing the minutes you may want your password to be “remembered”, or let in 0 so you will need to type your password each time you type sudo

Source

Pages: 1 2 3 4 5 6 7 8 9 Next