Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Saturday, May 7, 2016

which, whereis & locate

"which" command to find out if a relevant binary is already in your search path. For example: which php

"whereis" searches a broader range of system directories and is independent of your shell's search path.

"locate" consults a precompiled index of the file system to location filenames that match a particular pattern. "locate" can find any type of files as well, and its database is updated periodically by the updatedb command.

Tuesday, October 4, 2011

Remove duplicate lines with uniq

sort file.txt | uniq

To list the unique lines only: sort file.txt | uniq -u
To list the duplicated lines only: sort file.txt | uniq -d

Saturday, June 18, 2011

linux rename multiple files

Did you ever have this situation that you have multiple files like a.inc, b.inc, c.inc, and you want to change them to a.php, b.php, c.php? Basically, we want to change extensions of multiple files in linux - bulk rename files.

rename command can get this task done.

rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]

-v Verbose: print names of files successfully renamed
-n No Action: show what files would have been renamed
-f Force: overwrite existing files

perlexpr: Perl expression.  Well, this might be the headache to most users.

files: specify the pattern of the files that need to be renamed.

So, if we want to rename all files matching *.inc to *.php, we can do:

rename -v 's/.inc/.php/' *.inc

In this command, s means substitute. We want to substitute *.inc with *.php. The last *.inc means do the replacement to all files matching *.inc

Saturday, September 20, 2008

Accidently delete files on linux

Today I accidently delete some files of my project on linux. I wasn't panic because i think there must be some way to recover these files, such like what i did on Windows. I open my browser, google is my default home page. I typed 'recover deleted files on linux' and search. There are some solutions, however, they are all complicated! I thought maybe it is my keyword is not right, no matter all, i'm not a native english speaker. So i tried to search Chinese instead, the result disappointed me as well. It seems there is no easy way to recover deleted files on linux.

Then i became a little panic, what i have to do is to recreate those files again. I believe that is faster than i implement those complicated solutions.