LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 08-21-2018, 12:44 PM   #1
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 2,717
Blog Entries: 1

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
Hello one-liners!


I address in this way those who like to bash and try to avoid extensive use of scripts. So everyone is invited to post here its own one line (or maybe two line) compound command. Here what I mean
Code:
$ alias lspkg='ls /var/log/packages | grep '; lspkg pyth
this one-liner should list many python packages installed. Here more complicated example I just run
Code:
$ for f in $(ls *.c ) ; do if [ `wc -l $f | cut -d' ' -f1` -lt 200 ] ; then echo  $f ;  fi ; done
word of explanation: it just looks through c source files and picks those with less than 200 lines of code. Here is the output in coreutils/src directory
Code:
basename.c
coreutils-arch.c
coreutils-dir.c
coreutils-vdir.c
cp-hash.c
dirname.c
false.c
find-mount-point.c
force-link.c
getlimits.c
group-list.c
groups.c
hostid.c
hostname.c
lbracket.c
libstdbuf.c
link.c
logname.c
ls-dir.c
ls-ls.c
ls-vdir.c
mkfifo.c
nproc.c
operand2sig.c
printenv.c
prog-fprintf.c
readlink.c
relpath.c
sleep.c
true.c
tty.c
uname-arch.c
uname-uname.c
unlink.c
users.c
version.c
whoami.c
yes.c
Basically to be one-liner means for me to create such things on demand, definitely not to try to memorize or - even worse - put this in auto-magical script. Why I posting in this forum? Slackware is just very well suited for such way of work. I hope idea is quite clear.

Final word: I plan all these sources file to convert to pdf (text2pdf from slackbuilds) - to create one book - maybe with some comments of mine - and copy to my tablet - and of course read in my spare time. Of course for educational purposes.
 
Old 08-21-2018, 01:06 PM   #2
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
I keep all my useful (to me) "one-liners" on my github (for easy access on other systems). They aren't all exactly one-liners, but if they aren't, they're close. If I didn't write them myself, I credit those who did in the file. Here's two I think others might benefit from:

This one I keep as file in my /usr/local/bin and it can find the same lines in files even if they aren't in order.

Code:
perl -ne 'print if ($seen{$_} .= @ARGV) =~ /10$/' $1 $2
I use this to download videos from youtube and automatically get the highest quality audio and video while sticking with mp4 format. I just store it in a folder that I download all the videos to and I simply call it get

Code:
/usr/bin/youtube-dl -f bestvideo[ext=mp4]+bestaudio[ext=m4a] $@
 
1 members found this post helpful.
Old 08-21-2018, 01:44 PM   #3
rkfb
Member
 
Registered: Oct 2003
Location: Guildford, England
Distribution: Slackware64 15.0 running i3
Posts: 494

Rep: Reputation: 174Reputation: 174
A simple one:

Code:
cd ~/foo;clear;ls -lhB --color=auto;echo -ne "\n"
Change to the given directory and print a nice coloured list of the contents followed by a new line.
 
Old 08-21-2018, 02:24 PM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,322
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Sometimes people ask about "all" the programs installed.

Code:
apropos -w '*' | awk '$2=="(8)"||$2=="(1)"' | sort | less
 
Old 08-21-2018, 02:29 PM   #5
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Void, Linux From Scratch, Slackware64
Posts: 3,152

Rep: Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856Reputation: 856
Some bash aliases that I use all the time
Code:
alias search='find . \! -iname '\''*~'\'' -print |xargs grep -s --ignore-case --binary-files=without-match --line-number'
alias get='history|grep -i'
'search' search's all files in current folder for a string.
'get' searches the bash history for a string.

This is sort of a one liner
Code:
show ()
{
	top -bn1|grep -i "$1"|awk '{print $1}'|xargs ps -ww
}
But has to be in a function to pass the param, shows all running procs matching string.
 
Old 08-21-2018, 03:17 PM   #6
coralfang
Member
 
Registered: Nov 2010
Location: Bristol, UK
Distribution: Slackware, FreeBSD
Posts: 836
Blog Entries: 3

Rep: Reputation: 297Reputation: 297Reputation: 297
Recursively count the total number of lines inside every matching file;
Code:
function wccat() { grep -r --include "$@" . | wc -l; }
eg;
Code:
$ wccat *.cpp
5427

Also here's 2 more.

Grep for running process names
Code:
function psgrep() { ps axuf | grep -v grep | grep "$@"; }

Read the slackware changelog
Code:
function slackclog() { curl -s ftp://ftp.osuosl.org/pub/slackware/slackware64-current/ChangeLog.txt | more; }
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: 10 Useful Linux One-Liners for System Administrators LXer Syndicated Linux News 0 04-26-2015 05:44 PM
One liners for File system disk usage. sysmicuser Linux - Newbie 9 02-17-2012 09:02 AM
LXer: 3 Handy Commandlinefu One Liners LXer Syndicated Linux News 0 06-28-2010 07:11 PM
LXer: More Perl One Liners For Linux Or Unix LXer Syndicated Linux News 0 07-25-2008 06:50 AM
Using mv and grep together one liners DIRdiver Linux - General 7 07-07-2007 11:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration