Welcome Guest ( Log In | Register )

3 Pages  1 2 3 >Bottom

Outline · [ Standard ] · Linear+

 Any interesting commands in Linux?

views
     
TSFlierMate
post Sep 28 2021, 10:17 PM, updated 2y ago

On my way
****
Validating
543 posts

Joined: Nov 2020
Any interesting commands in Linux?

Let's start with me:

To display a pop-up notification message:
CODE
notify-send <message>


user posted image

To display CPU info, just dump the text file "cpuinfo":
CODE
cat /proc/cpuinfo


user posted image

Anymore, anyone?

For example, how do you display a message dialogbox using bash script?

This post has been edited by FlierMate: Sep 28 2021, 10:18 PM
TSFlierMate
post Oct 2 2021, 04:16 PM

On my way
****
Validating
543 posts

Joined: Nov 2020
This is how I convert myself from non-privileged user to privileged user with "sudo" access.
Is this the recommended way to do it?

Reference: Chapter 1. GNU/Linux tutorials

Initially, in a newly installed Debian, I am not a privileged user.

CODE
boo@debian:~$ sudo -l
[sudo] password for boo:
Sorry, user boo may not run sudo on debian.


The "culprit" is the configuration file at /etc/sudoers

I could not change the ownership, as seen below, unless I access with "su"(superuser?) and change the ownership using "chown".
Then, I add myself to the /etc/sudoers configuration file.

CODE
boo@debian:/etc$ chown boo sudoers
chown: changing ownership of 'sudoers': Operation not permitted
boo@debian:/etc$ root
-bash: root: command not found
boo@debian:/etc$ su
Password:
root@debian:/etc# chown boo sudoers
root@debian:/etc# exit
exit
boo@debian:/etc$ ls -l sudoers
-r--r----- 1 boo root 669 Feb 27  2021 sudoers
boo@debian:/etc$ echo "boo  ALL=(ALL) ALL" >> /etc/sudoers
boo@debian:/etc$ sudo
sudo: /etc/sudoers is owned by uid 1000, should be 0
sudo: no valid sudoers sources found, quitting
sudo: error initializing audit plugin sudoers_audit
boo@debian:/etc$ echo "boo  ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers


But /etc/sudoers must be owned by "root" before I can run as "sudo", so I access with "su" and revert the ownership from myself to "root".

CODE
oo@debian:/etc$ sudo
sudo: /etc/sudoers is owned by uid 1000, should be 0
sudo: no valid sudoers sources found, quitting
sudo: error initializing audit plugin sudoers_audit
boo@debian:/etc$ su
Password:
root@debian:/etc# chown root /etc/sudoers
root@debian:/etc# exit
exit


Voila, now I can run as "sudo" privileged access.

CODE
oo@debian:/etc$ sudo whoami
root
boo@debian:/etc$ sudo apt-get update
Hit:1 http://security.debian.org/debian-security bullseye-security InRelease
Hit:2 http://deb.debian.org/debian bullseye InRelease
Get:3 http://deb.debian.org/debian bullseye-updates InRelease [39.4 kB]
Fetched 39.4 kB in 6s (6,472 B/s)                                              
Reading package lists... Done



angch
post Oct 3 2021, 11:53 AM

On my way
****
Junior Member
635 posts

Joined: Jul 2006
Some newer non-standard ones we use these days:

ripgrep. Grep, but stupid fast.

tokei. Lines of code counter. Fast.

exa. Better ls

zstd. Because it's stupid fast and produces smaller files than gzip, uses all cores for compression (without changing output), can adapt compression to I/O speed.

wrk. Web bench. Good for quick sanity checks on performance.

jq. For pretty printing (mostly) JSON.

Others other folks use, but I don't

parallel. GNU Parallel, to run things in parallel, when lazy.

bat. Better cat, with syntax highlighting.

fd. Better find than find.

The usual ones not taught in LPI, etc:

tmux. screen. Pick one.

htop. Better top.

vmstat. Poor man's fast system perf diagnostics.

iotop. Ditto, but for I/O.

strace. To figure out which what's happening with that slow process.

xz. For extreme compression for archival.

open. Open the selected file or directory with configured program, based on MIME-type.

xdg-open. Like open, but with desktop programs.
CODE
xdg-open ~
to launch your file manager on home directory. Mix and match with `find` and other command lines for fun stuff.

Not a command, but
CODE
cd -
changes to your previous current (haha) directory.
CODE

cd ~/myproject
cd /usr/local/something
cd - # goes back to ~/myproject


curl. For low level command line http/https stuff.

wget. For when curl sucks, and you want wildcard support.
CODE
wget www.download.example.com/dir/{version,old}/package{00..99}.rpm
ftw.

strings. Poor man's CTF util.

file. When you want file magic to tell you what file it actually is.

Other misc stuff.

docker. Stupid heavy for some stuff, but some stuff is cleaner via docker, and docker-compose.

git. Even for your /etc/

wireguard. Better vpn than openvpn.

mc. minio. When you wanna run your own S3 object store. Very fun when combined with zstd


This post has been edited by angch: Oct 3 2021, 12:21 PM
angch
post Oct 3 2021, 12:04 PM

On my way
****
Junior Member
635 posts

Joined: Jul 2006
QUOTE(FlierMate @ Sep 28 2021, 10:17 PM)
For example, how do you display a message dialogbox using bash script?
*
apt-get install dialog
angch
post Oct 3 2021, 12:08 PM

On my way
****
Junior Member
635 posts

Joined: Jul 2006
QUOTE(FlierMate @ Oct 2 2021, 04:16 PM)
This is how I convert myself from non-privileged user to privileged user with "sudo" access.
Is this the recommended way to do it?
CODE

sudo usermod -a -G sudo newadminuser


Is how I promote a normal user to sudo user in Ubuntu. Should be same as debian's setup.

CODE

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL


That's because of the above rule by default in /etc/sudoers

This post has been edited by angch: Oct 3 2021, 12:09 PM
angch
post Oct 3 2021, 12:27 PM

On my way
****
Junior Member
635 posts

Joined: Jul 2006
Also, nice that you wrote your own, but we usually lazily just do

CODE

angch@rick:~$ od -A x -t x1z -v hello | head
000000 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00  >.ELF............<
000010 02 00 3e 00 01 00 00 00 a0 c1 45 00 00 00 00 00  >..>.......E.....<
000020 40 00 00 00 00 00 00 00 78 4e 12 00 00 00 00 00  >@.......xN......<
000030 00 00 00 00 40 00 38 00 07 00 40 00 0e 00 0d 00  >....@.8...@.....<
000040 06 00 00 00 04 00 00 00 40 00 00 00 00 00 00 00  >........@.......<
000050 40 00 40 00 00 00 00 00 40 00 40 00 00 00 00 00  >@.@.....@.@.....<
000060 88 01 00 00 00 00 00 00 88 01 00 00 00 00 00 00  >................<
000070 00 10 00 00 00 00 00 00 04 00 00 00 04 00 00 00  >................<
000080 9c 0f 00 00 00 00 00 00 9c 0f 40 00 00 00 00 00  >..........@.....<
000090 9c 0f 40 00 00 00 00 00 64 00 00 00 00 00 00 00  >..@.....d.......<

for hex dumps

CODE
alias hexdump="od -A x -t x1z -v"


And there's also https://github.com/sharkdp/hexyl which is now in Debian buster.

grep -> ripgrep
od -> hexyl

This post has been edited by angch: Oct 3 2021, 12:34 PM
TSFlierMate
post Oct 4 2021, 03:30 PM

On my way
****
Validating
543 posts

Joined: Nov 2020
QUOTE(angch @ Oct 3 2021, 12:27 PM)
.......
*
Thank you, angch, for the great number of commands. I will keep this for reference.

Good to know you are a Linux enthusiast!
TSFlierMate
post Oct 4 2021, 03:34 PM

On my way
****
Validating
543 posts

Joined: Nov 2020
QUOTE(angch @ Oct 3 2021, 12:08 PM)
CODE
sudo usermod -a -G sudo newadminuser


Is how I promote a normal user to sudo user in Ubuntu. Should be same as debian's setup.


*
Just want to comment on this one: My issue was, I can't use "sudo" as a non-privileged user, and I am the only user.

So , I end up with that solution. The other solution is go to recovery mode in boot menu, but I forgot the commands to type there.

Thank you, nevertheless. biggrin.gif
acbc
post Oct 4 2021, 03:34 PM

Look at all my stars!!
*******
Senior Member
8,475 posts

Joined: Jan 2003
Been scratching my head to get W7 or W10 to see my Ubuntu shares. Tried everything and none worked. Ubuntu can access Windows shares using the built-in Files app.
angch
post Oct 4 2021, 04:54 PM

On my way
****
Junior Member
635 posts

Joined: Jul 2006
QUOTE(FlierMate @ Oct 4 2021, 03:34 PM)
Just want to comment on this one: My issue was, I can't use "sudo" as a non-privileged user, and I am the only user.

So , I end up with that solution. The other solution is go to recovery mode in boot menu, but I forgot the commands to type there.

Thank you, nevertheless.  biggrin.gif
*
Can I see your
CODE
groups
output, from your only user?

Your installation probably has root logins allowed, and you should login as root to get your usual user access to
CODE
sudo


This post has been edited by angch: Oct 4 2021, 04:55 PM
anakkk
post Oct 4 2021, 04:55 PM

Regular
******
Senior Member
1,565 posts

Joined: Apr 2013
rm -rf
TSFlierMate
post Oct 4 2021, 05:42 PM

On my way
****
Validating
543 posts

Joined: Nov 2020
QUOTE(angch @ Oct 4 2021, 04:54 PM)
Can I see your
CODE
groups
output, from your only user?

Your installation probably has root logins allowed, and you should login as root to get your usual user access to
CODE
sudo

*
Here it is:
user posted image

Anyway, I can run "sudo" now after typing the commands stated earlier.
TSFlierMate
post Oct 4 2021, 06:03 PM

On my way
****
Validating
543 posts

Joined: Nov 2020
QUOTE(acbc @ Oct 4 2021, 03:34 PM)
Been scratching my head to get W7 or W10 to see my Ubuntu shares. Tried everything and none worked. Ubuntu can access Windows shares using the built-in Files app.
*
No idea. I know my previous Win 10 also could not see my Ubuntu files, but never bother figure how.

Anyone with solution to this?

QUOTE(anakkk @ Oct 4 2021, 04:55 PM)
rm -rf
*
It will recursively delete a directory and all its contents and forcibly delete files without asking.

Kool, but use with caution. thumbsup.gif
angch
post Oct 4 2021, 08:50 PM

On my way
****
Junior Member
635 posts

Joined: Jul 2006
More useful commands, sysadmin perspective.

dmidecode. Dump DMI (BIOS) information, for low level hardware info.

lsblk. List out your virtual and physical media. Very useful when you do fancy LVM, DM-RAID and/or bcache stuff.

lspci, lsmem, lslocks, lsof, lshw. All very useful lowlevel info.

convert, and the usual ImageMagick toolkit.

nmap, netstat. For debugging networking stuff.

ethr. For network benchmark when you don't wanna use iperf.

smartctl, hdparm. For drive management stuff.

fail2ban. For slowing down script kiddies.

This post has been edited by angch: Oct 4 2021, 08:54 PM
GOPI56
post Oct 4 2021, 09:13 PM

Regular
******
Senior Member
1,396 posts

Joined: Dec 2012
QUOTE(acbc @ Oct 4 2021, 01:34 AM)
Been scratching my head to get W7 or W10 to see my Ubuntu shares. Tried everything and none worked. Ubuntu can access Windows shares using the built-in Files app.
*
To do that, you will need to set up Samba on Ubuntu:



This post has been edited by GOPI56: Oct 4 2021, 09:14 PM
TSFlierMate
post Oct 14 2021, 05:50 PM

On my way
****
Validating
543 posts

Joined: Nov 2020
In Linux, it is possible even to set sound volume through command in terminal window.

Increase :
CODE
$ amixer set Master 8%+


Decrease :
CODE
$ amixer set Master 8%-


user posted image

Found it online (Xah Lee's Linux tutorial).
TSFlierMate
post Oct 14 2021, 05:52 PM

On my way
****
Validating
543 posts

Joined: Nov 2020
QUOTE(angch @ Oct 4 2021, 08:50 PM)
More useful commands, sysadmin perspective.
....
lspci, lsmem, lslocks, lsof, lshw. All very useful lowlevel info.

*
And "lscpu" too!

Which is almost identical to "cat /proc/cpuinfo"

Cheers!
angch
post Oct 15 2021, 04:25 PM

On my way
****
Junior Member
635 posts

Joined: Jul 2006
And if it isn't obvious yet:

asciinema. For when you're too lazy to document and "script" is too crappy.
TSFlierMate
post Oct 15 2021, 06:55 PM

On my way
****
Validating
543 posts

Joined: Nov 2020
QUOTE(angch @ Oct 15 2021, 04:25 PM)
And if it isn't obvious yet:

asciinema. For when you're too lazy to document and "script" is too crappy.
*
Cool stuff! Thanks for introducing it.

Some examples of mine:
» Click to show Spoiler - click again to hide... «


This post has been edited by FlierMate: Oct 15 2021, 06:55 PM
ceciliatang95
post Oct 18 2021, 08:36 AM

Getting Started
**
Junior Member
67 posts

Joined: Oct 2021


Hi~

Thanks for the input here forumers.
I just started Linux myself, here are some useful ones:

CODE
df -h

For revealing disk space and usage, pretty useful if for server admins.
Make sure check out the /var/logs, majority of the legacy server at my company has /var/logs of 2GB

CODE
du -s

Check the file usage of your current folder

CODE
cd -

Change directory to your previous directory. Say if you were at /home/foo/bar and then cd to /var/log/audit, you can use cd - to instantly return to /home/foo/bar/

CODE
truncate -s (number) (size) (file)

Truncate a file size, useful if the Linux cannot even use rm -rf due to full disk space.
Sample: truncate -s 10k app.log

Hope it helps.

3 Pages  1 2 3 >Top
 

Change to:
| Lo-Fi Version
0.0153sec    0.34    5 queries    GZIP Disabled
Time is now: 29th March 2024 - 12:36 AM