coreutils

Forum rules
Share your brain ;)
machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

coreutils

Unread post by machinebacon » Thu Dec 31, 2015 2:59 pm

We have a Shell Tips & Tricks section which actually covers the builtins of your shell. This section here shows the power of coreutils:

Code: Select all

  [ arch base64 basename cat chcon chgrp chmod chown chroot cksum comm
  coreutils cp csplit cut date dd df dir dircolors dirname du echo env
  expand expr factor false fmt fold groups head hostid hostname id install
  join kill link ln logname ls md5sum mkdir mkfifo mknod mktemp mv nice nl
  nohup nproc numfmt od paste pathchk pinky pr printenv printf ptx pwd
  readlink realpath rm rmdir runcon seq sha1sum sha224sum sha256sum sha384sum
  sha512sum shred shuf sleep sort split stat stdbuf stty sum sync tac tail
  tee test timeout touch tr true truncate tsort tty uname unexpand uniq
  unlink uptime users vdir wc who whoami yes
So let's see if we can collect some tips & tricks here, too.
..gnutella..

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: coreutils

Unread post by machinebacon » Thu Dec 31, 2015 3:03 pm

Code: Select all

           _   
  ___ __ _| |_ 
 / __/ _` | __|
| (_| (_| | |_ 
 \___\__,_|\__|
               
Merge multiple MP3 to one
Heck, there are programs like mp3wrap or sox, but the best and fastest merging tool for mp3s (or any other audio files) is already there in coreutils. This probably does not work if the bitrates are changing.

Code: Select all

cat song_1.mp3 song_2.mp3 song_3.mp3 song_4.mp3 > side_a.mp3
Bonus tip: if you want to create a slideshow for youtube (so, music and an image), ffmpeg can do that for you:

Code: Select all

ffmpeg -loop 1 -i image.jpg -i side_a.mp3 -c:v libx264 -c:a copy -strict experimental -shortest slideshow.mp4

Create live USB from ISO
This replaces tools like dd. Useful if you want to put an ISO on a device

Code: Select all

cat linuxbbq_anorexicteen.iso /dev/sdb

Live heredoc
This replaces the touch command. If there is no busybox vi or nano available (lol), you can use cat to create files. It takes stdin until you press Ctrl-d

Code: Select all

cat >README.txt

Line Numbering
Nothing special, some people like to have line numbering because they use ed to edit files (lol, NOT!)

Code: Select all

cat -n README.txt
..gnutella..

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: coreutils

Unread post by dkeg » Thu Dec 31, 2015 3:40 pm

Wow. First, I'm surpirsed we have not yet made this thread. Second, I use coreutils everyday, well, at least I thought I was.
What comes first, a need, thus searching and finding a solution which uses a command that we all use often, OR, learning new ways to use a command we use almost daily and looking for use cases to try it out.

Work hard; Complain less

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: coreutils

Unread post by rhowaldt » Thu Dec 31, 2015 5:44 pm

what drew said. also, some really cool things with cat. did not know it could replace dd. why is there no tool called dog, and if there was what would it do?

here's another cool thing you can do with cat:

Code: Select all

cat bla.txt | grep "anus"
awesome. some more useless stuff here.

sorry i don't have any proper tricks :)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
ChefIronBelly
Approved BBQer
Posts: 1044
Joined: Mon Jan 13, 2014 6:01 am
Location: Michigan

Re: coreutils

Unread post by ChefIronBelly » Sat Jan 02, 2016 8:19 pm

there is also my shitey script called CatSSH

http://linuxbbq.org/bbs/viewtopic.php?f=15&t=2188
(1/1) Installing: LinuxBBQ...................................[69%]==============[/]

User avatar
wuxmedia
Grasshopper
Posts: 6445
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: coreutils

Unread post by wuxmedia » Sun Jan 03, 2016 12:45 pm

'bout the only one I can think of and use daily:

Code: Select all

mv public_html hacked_public_html_`date -I`
Most people use

Code: Select all

date +%F
which frankly I still can't recall.
(it appends a nice full ISO date, 2016-01-03)
or using cat at work:

Code: Select all

 cat big_data.sql | mysql -u root -p big_data
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
doubledutch
killall X
Posts: 163
Joined: Sun Aug 10, 2014 1:25 pm

Re: coreutils

Unread post by doubledutch » Mon Jan 04, 2016 7:08 pm

I'm quite fond of the command:

Code: Select all

time cat
What day does Christmas fall on, this year?

Code: Select all

date --date='25 Dec' +%A

User avatar
ivanovnegro
Minister of Truth
Posts: 5448
Joined: Wed Oct 17, 2012 11:12 pm

Re: coreutils

Unread post by ivanovnegro » Mon Jan 04, 2016 9:31 pm

I think we always use cat to see what our sources list looks like:

Code: Select all

cat /etc/apt/sources.list
When playing with files I often use the rm command:

Code: Select all

rm
wipes the file and:

Code: Select all

rm -r
wipes an entire directory.

But you already know this. ;) coreutils is such a powerful tool in general.

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: coreutils

Unread post by machinebacon » Tue Jan 05, 2016 6:26 am

Code: Select all

df -hl
shows a summary of local disk usage in human readable format

Code: Select all

du -sh ~/.local/share/
du -sh ~/README
shows the disk usage of the directory (or file) in human readable format

Code: Select all

comm FILE1 FILE2
you don't really need 'diff' because 'comm' can do the same, basically

Code: Select all

head -n 10 /etc/inittab
head shows the first n lines of a file, in our case we will know what default runlevel we boot to by default

Code: Select all

tail -f /dev/kmsg
this follows changes at the end of a certain file, in our case the kernel ring buffer (we know this from syslog and dmesg, which is part of util-linux)

Code: Select all

paste FILE1.txt FILE2.txt > FILE_ALL.txt
pastes the content two files, line by line. it is not the same as using cat which pastes file after file. probably useful for databases if you change the delimiter (-d), eg. for CSV
..gnutella..

Post Reply