Skip to content
Advertisement

Tag: unix

Program configuration data in Unix/Linux

What is recommended way to keep a user configuration data in Unix/Linux? My programming language is C++. Configuration data will be kept in XML/text/binary format, I have no problem with handling such files. I want to know where can I keep them. For example, in the Windows OS configuration data may be kept in the Registry (old way) or in

Oldest code in a typical Linux distro

Just out of curiosity: What’s the oldest code/package in a typical linux distro? Emacs? GCC? Answer Sun RPC is pretty old, and it’s in the C library: http://blogs.oracle.com/webmink/entry/old_code_and_old_licenses

How to find directories with the name of specific length

How could I find directories with the name of specific length? For example, I have bunch of directories which have length of the name equal to 33 chars (‘a92e8cc611fdebcca3cf2fc8dc02c918’, ‘c442fb3f46d6c8bd17d27245290a9512’ and so on). Does find utility accepts condition in form of the ‘wc -c’? Or maybe some other utilities should be piped together? Answer few ways with GNU find

Sorting a tab delimited file

I have a data with the following format: Now I tried to sort the file based on the last field decreasingly. I tried the following commands but it wasn’t sorted as we expected. What’s the right way to do it? Here is the sample data. Answer Using bash, this will do the trick: Notice the dollar sign in front of

Padding Empty Field in Unix Join Operation

I have two files where I want to perform union operation based on 1st column: file1.txt file2.txt The result I hope to get is like this: where the empty fields of column 1 is padded with “-“. But why this join command doesn’t work as I expected? What’s the right way to do it? Answer “Important: FILE1 and FILE2 must

Add up a column of numbers at the Unix shell

Given a list of files in files.txt, I can get a list of their sizes like this: which produces something like this: How can I get the total of all those numbers? Answer is the shortest one I’ve found (from the UNIX Command Line blog). Edit: added the – argument for portability, thanks @Dogbert and @Owen.

Replacing String Columnwise Using Sed

Given this data I want to replace the string at 2nd column into “” if it is “qux”. Resulting: How do you do that with sed? In particular the data is very big with ~10^7 lines Answer I wouldn’t actually do it with sed since that’s not the best tool for the job. The awk tool is my tool of

What is the safest way to empty a directory in *nix?

I’m scared that one day, I’m going to put a space or miss out something in the command I currently use: Is there a safer way of emptying the current directory’s contents? Answer The safest way is to sit on your hands before pressing Enter. That aside, you could create an alias like this one (for Bash) alias rm=”pwd;read;rm” That

Advertisement