User Tools

Site Tools


en:linux:useful

Linux commands I find useful

View end of an appending file

tail -f filename

Find files under ''top_directory'' with ''mask''

find top_directory -name mask

Look for word ''keyword'' in files under directory ''dir'' with mask ''mask''

grep keyword `find dir -name mask`

or a bit easier (without mask), the -I excludes binary files

grep -r -I keyword dir

Undelete/file recovery on ext3/reiserfs

There is no undelete utility. The only chance is to grep your disk and search for some phrases which were in your lost document.

  1. Unmount the partition (to prevent overriding you data). If not possible, boot from a CD (e.g. Knoppix).
  2. Try out the following command (I found it somewhere on the net)
    grep --binary-files=text -300 "the search phrase" /dev/sda1 > output

    The -300 switch gives the size of block (around found phrase) to be saved to the output file.

How to reset all environment variables

In bash

unset -v $(env | sed 's/\([A-Z_0-9]*\)=.*/\1/')

in tcsh

set bla=`env | sed 's/\([A-Z_0-9]*\)=.*/\1/'` ; unsetenv ${bla}

How to process output of a command line by line

while read line
do
	echo "line = $line"
done < <(cvs update -d 2>&1)

Advantage: the loop is not run in subshell and hence in its body one can modify shell variables.

The 2>&1 redirects stderr to stdout which it turn means that also error output goes through the while loop.

Colorful echo

echo -e "\033[00;31mUNKNOWN FILES\033[00m"

For more information see article Paint your bash.

grab sound from a flash file

ffmpeg -i <your_input_video>.flv -vn -acodec copy <your_output_file>.mp3

The flash files often miss the flv suffix. Often, then can be found by

ll /tmp|grep Flash

How to launch Konsole with predefined tabs

See my work_konsole script and tabs definition file. A bit more details can be found in The Konsole Handbook.

pwd -P

date/time - timestamp conversions

  • date/time to timestamp
date -d "Oct 20 12:00:00 CEST 2011" +%s
  • timestamp to date/time
date -d @1319104800
en/linux/useful.txt · Last modified: 2011/10/21 14:21 (external edit)