commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
searching for sed to make a csv, I found the solution from Mr. Stolz in http://funarg.nfshost.com/r2/notes/sed-return-comma.html
you can also to use:
tr "\n" "," ;
But I was looking for a sed way =)
Even though --color is an option for 'ls' it will not display in color when doing 'ls -lah --color=always | less' to have color output when doing a directory listing and piping it out to page through results, replace less with most.
To install most if not installed, run:
sudo apt-get install most
If you gzip an empty file it becomes 20 bytes. Some backup checks i do check to see if the file is greater than zero size (-s flag) but this is no good here. Im sure someone has a better check than me for this? No check to see if file exists before checking it's size.
The command gives size of all files smaller than 1024k, this information, together with disk usage, can help determin file system parameter (e.g. block size) or storage device (e.g. SSD v.s. HDD).
Note if you use awk instead of "cut| dc", you easily breach maximum allowed number of records in awk.
This command is meant to be used to make a lightweight backup, for when you want to know which files might be missing or changed, but you don't care about their contents (because you have some way to recover them).
Explanation of parts:
"ls -RFal /" lists all files in and below the root directory, along with their permissions and some other metadata.
I think sudo is necessary to allow ls to read the metadata of certain files.
"| gzip" compresses the result, from 177 MB to 16 MB in my case.
"> all_files_list.txt.gz" saves the result to a file in the current directory called all_files_list.txt.gz. This name can be changed, of course.
Useful if a different user cannot access some directory and you want to know which directory on the way misses the x bit.
If you want all the URLs from all the sessions, you can use :
perl -lne 'print for /url":"\K[^"]+/g' ~/.mozilla/firefox/*/sessionstore.js
Thanks to tybalt89 ( idea of the "for" statement ).
For perl purists, there's JSON and File::Slurp modules, buts that's not installed by default.
Require "grep -P" ( pcre ).
If you don't have grep -P, use that :
grep -Eo '"url":"[^"]+' $(ls -t ~/.mozilla/firefox/*/sessionstore.js | sed q) | cut -d'"' -f4
This command lists extended information about files, i.e. whether or not it is a true file or link, who owns it, etc. without having to 'ls' from the specific directory. If you know the filename, but not the location, this helps with finding other information about the file. It can be truncated by creating an alias for 'ls -l'. The sample output shows difference in regular locate vs. ls + locate.
This command lists the names of your USB devices connected and what file in /dev they are using. It's pretty useful if you don't have an automount option in your desktop or you don't have any graphical enviroment.
no need to use grep.
Many competing commands to do this, but since most people want a Long list with Human readable files sizes and want to see All files (including hidden (.*) files) this one wins on simplicity and usefulness. Plus grep is just as, if not more portable than sed or awk, and is more widely understood. :)
ls -l may vary depending on operating system, so "print $8" may have to be changed
For this example, all files in the current directory that end in '.xml.skippy' will have the '.skippy' removed from their names.
Must have the video open and fully loaded.
This is useful for paging through long directories, mulitple directories, etc. I put this in my ~/.bash_aliases file and alias 'lsl' to it.
it does provide much more information , the owner , group , the size in byte , and the last modified time a file or directory was
ls -al : list all in long format