recentpopularlog in

kme : unix   478

« earlier  
bash - How to check if a process id (PID) exists - Stack Overflow
Looks like 'ps -p $PID' is the way to go; 'kill -0 $PID' has caveats.
unix  linux  sysadmin  processmanagement  shellscripting 
4 days ago by kme
ssh agent - ssh-add under cygwin - Server Fault
I totally did this.

OK, that other Serverfault.com answer has a typo.

The right thing you want to run is:
<code class="language-bash">eval `ssh-agent`</code>
ssh-agent spits out a bunch of shell statements to set environmental variables. The eval runs them in the current shell. You can invoke ssh-agent that way, or run ssh-agent and then copy-paste its output into your current shell for the same effect.
ssh  ssh-agent  cygwin  linux  unix  doh  solution 
4 days ago by kme
hard drive - Disk usage per user in Linux / Unix - Server Fault
<code class="language-bash">find . -type f -printf "%u %s\n" \
| awk '{user[$1]+=$2}; END{for(i in user) print i,user[i]}'</code>
diskusage  sysadmin  linux  unix  solution 
4 weeks ago by kme
find disk usage per user on a filesystem
<code class="language-bash">find / -printf "%u %s\n" \
| awk '{user[$1]+=$2}; END{ for( i in user) print i " " user[i]}'</code>
bash  unix  sysadmin  diskusage  quota  storage  solution 
4 weeks ago by kme
macos - Add a locale in Mac OSX - Stack Overflow
Looking into this found that, as of Mac OS X 10.10.3, collation is still broken for Spanish and most European languages. Collation definitions for these locales are linked to an ASCII definition. This ends up breaking things such as ORDER BY clauses on PostgreSQL.


Also, WTF is does 'la_LN' mean anyway?
macos  elcapitan  annoyance  sorting  brokenness  collation  lc_all  dateandtime  unix  maybesolution 
11 weeks ago by kme
Th Most Handy du (Disk Usage) Commands in Linux - Make Tech Easier
Honestly did not know about the '--threshold' or exclusion options.
sysadmin  diskspace  unix  linux  du  tipsandtricks 
12 weeks ago by kme
newlines - What's the point in adding a new line to the end of a file? - Unix & Linux Stack Exchange
Example: the output of GNU sort always ends with a newline. So if the file foo is missing its final newline, you'll find that sort foo | wc -c reports one more character than cat foo | wc -c.

Not necessarily the reason, but a practical consequence of files not ending with a new line:

Consider what would happen if you wanted to process several files using cat. For instance, if you wanted to find the word foo at the start of the line across 3 files:
<code class="language-bash">cat file1 file2 file3 | grep -e '^foo'</code>
newlineterminator  unix  textfiles  textprocessing  explained 
july 2019 by kme
stdout - How to make output of any shell command unbuffered? - Stack Overflow


Try stdbuf, included in GNU coreutils and thus virtually any Linux distro. This sets the buffer length for input, output and error to zero:
<code class="language-bash">stdbuf -i0 -o0 -e0 command</code>


This totally works for something like this:
<code class="language-bash">stdbuf -i0 -o0 -e0 find . -name 'core*' -printf '%f\t%s\n' | head</code>
bash  shellscripting  pipes  unix  buffering  solution 
july 2019 by kme
windows - How to fix PuTTY showing garbled characters? - Server Fault
The analogous fix on CentOS (7) is to use 'localectl', maybe, except that requires DBus to be running, which it isn't for a fresh-out-of-the-box Docker container. ¯\_(ツ)_/¯
If the locale returns something like POSIX, issue
<code class="language-bash">update-locale LANG=en_US.utf8</code>
at the command line - see thomas-krenn.com/de/wiki/Locales_unter_Ubuntu_konfigurieren – koppor Dec 19 '15 at 11:05
docker  utf8  characterencoding  locale  mojibake  terminal  unix  shell  ubuntu  solution  centos  sortof 
june 2019 by kme
umask - cmdline Unix Permissions bits calculator - Unix & Linux Stack Exchange
Useful for this tidbit alone:
<code class="language-bash">printf '%o\n' "$((value ^ 511))"</code>
unix  sysadmin  permissions  permissionbits  posixbits  bashscripting  calculator 
june 2019 by kme
Abundant Scripting Is Good | UNIX Scripting Tips and Ideas - Kimball Hawkins
I doubt there is any System Administrator out there who doesn't realize that scripting is good, but I've found there are few who actually use scripting as I feel it should be used -- as a way to programatically improve, simplify and automate many of the complex and tedious tasks of system monitoring and maintenance.…

My first rule is, if I have to do any task more than once, I’ll script it. This applies especially if errors in the command can have serious consequences.

My second rule is, if I’m going to script it, I’m going to make it robust enough to be useful in all applicable situations.

My third rule is I never hard-code specific information in a script if I can help it.

Fourth is: If a script can figure something out, don’t require the user to enter it, or choose it or find it.

Fifth is: Document it!
sysadmin  shellscripting  unix  linux  bash 
june 2019 by kme
yest download | SourceForge.net
Needs to be modified to support 'now', or 'today' as starting time/dates.
Download yest for free. This is a command line date/time manipulation and formatting program, very useful in scripts. You can easily add or subtract days, hours and/or minutes from a specified date.
timeanddate  unix  c  shellscripting  commandline  essential  movein  needshelp 
june 2019 by kme
Bash scripting cheatsheet
Has links to the Bash Hackers wiki, which are helpful.

Has a really good reference for array / associative array syntax, too!
bash  shellscripting  cli  unix  linux  cheatsheet  fuckina 
may 2019 by kme
unix - tar – extract discarding directory structure - Super User | https://superuser.com/
If you just want to remove a few path segments, then --strip-components=n or --strip=n will often do:
<code class="language-bash">
tar xvzf tgz --strip=1
</code>
unix  linux  sysadmin  tar  archive  backupandrecovery  solution 
may 2019 by kme
The Computer Chronicles - UNIX (1985) - YouTube | https://www.youtube.com/

Stewart Cheifet: ... Why is there sudden excitement about UNIX?

Gary Kildall: Well it shouldn't be a sudden excitement--UNIX itself has been around since the late 60s. The problem is that micros haven't had the power to support... they haven't had the large amount of main memory, the hard disk, the fast processor, and so forth, but nowadays micros do have that power, and so UNIX becomes a serious contender for an operating system standard.

OK, in fact many people are saying UNIX become *the* standard operating system of the future, but there are *many* uses of UNIX going on right now. We have a report....
unix  history  computing  video 
may 2019 by kme
domain - Create Unix Named Socket from the Command Line - Server Fault | https://serverfault.com/
For supervisord, I thought I had to create the Unix domain socket, and I also thought that it was the same as a FIFO (named pipe). Nope. To both.
fifo  namedpipe  socket  unixdomainsocket  unix  solution 
may 2019 by kme
Intrepid command line directory traversal - BrettTerpstra.com | https://brettterpstra.com/
I use Terminal (well, iTerm 2) for file management on my Mac more often than I use Finder. Typing out long path names is often more tedious than drilling through Finder folders, though. I have enough
unix  shell  bash  commandline  filesystemnavigation  tipsandtricks 
april 2019 by kme
Example for renaming foo? does not work as described · karelzak/util-linux@ed21c47 | https://github.com/
Was so scratching my head about this, turned out it was fixed in util-linux 2.33.1, which my Linux distro just hadn't upgraded to yet.
manpage  unix  linux  utility  software  sysadmin  solution 
march 2019 by kme
permissions - How to chmod without /usr/bin/chmod? - Unix & Linux Stack Exchange | https://unix.stackexchange.com/
You can run the loader directly, and pass it the command you want to run:
<code class="language-bash">
/lib/ld-linux.so /bin/chmod +x /bin/chmod
</code>

Your path to the loader might vary. On a 64-bit system you need to choose the right one based on how chmod was compiled; the 64-bit version is named something like /lib64/ld-linux-x86-64.so.2

The chmod utility relies on the chmod() system call (see man 2 chmod). So you could do this with a few lines of C, or just about any other language that has a wrapper around it (which would be most of them). Very few *nix systems are going to lack a C compiler and a perl interpreter; most linux distros require the later to work.
<code class="language-bash">
perl -e 'chmod 0755, "foobar.file"'
</code>
linux  unix  sysadmin  chmod  tipsandtricks  disasterrecovery 
march 2019 by kme
history - Why is the xargs -i option deprecated? - Unix & Linux Stack Exchange | https://unix.stackexchange.com/
This makes me feel old, because I remember when 'xargs' *only* had '-i' and '-l', and this change feels completely arbitrary to me.
The -l and -i options appear in the 1997 version of the POSIX standard, but do not appear in the 2004 version of the standard. Therefore you should use -L and -I instead, respectively.
xargs  unix  shellscripting  posix  explained  solution 
march 2019 by kme
pipe - cryptsetup: Attaching loopback device failed - Unix & Linux Stack Exchange | https://unix.stackexchange.com/
It seems that cryptsetup requires the LUKS header to be either regular file or device. If you need to provide the LUKS header as an output from a process/stream, you can easily circumvent the restriction by sending it to /dev/ram
<code class="language-bash">
cat LUKS-HEADER > /dev/ram0
</code>

(provided that your kernel supports ramdisk)

Then you can then simply use your cryptsetup command as:
<code class="language-bash">
cryptsetup luksOpen /dev/sdb1 sdb1 --header /dev/ram0
</code>

Keep in mind, the LUKS header will stay in /dev/ram0 disk until you free up the space. To free up the memory, you can use the blockdev command:
<code class="language-bash">
blockdev -v --flushbufs /dev/ram0
</code>
luks  crypto  blockdevices  linux  unix  sysadmin  tipsandtricks 
march 2019 by kme
linux - how to kill the tty in unix - Stack Overflow | https://stackoverflow.com/
This was essentially what I needed
<code class="language-bash">ps -ft pts/6 -t pts/9 -t pts/10</code>

And my actual command line looked like this:
<code class="language-bash">
# probably could've done this with just 'who -al' instead of who + ps
who | grep userid \
| awk '{print $2}' \
| parallel 'ps -ft {} \
| tail -n +2' \
| awk '{print $2}'
| xargs kill -HUP</code>

And with some refinement, I was able to do something like this:
<code class="language-bash">
who -al | grep old \
| awk '{print $7}' \
| sudo xargs kill -HUP</code>

Also:
I had the same question as you but I wanted to kill the gnome terminal which I was in. I read the manual on "who" and found that you can list all of the sessions logged into your computer with the '-a' option and then the '-l' option prints the system login processes.
<code class="language-bash">who -la</code>

Also:
<code class="language-bash">pkill -9 -t pts/0</code>
unix  linux  sysadmin  pseudoterminal  processmanagement  solution 
march 2019 by kme
macos - Why CURL return and error (23) Failed writing body? - Stack Overflow | https://stackoverflow.com/

(For completeness and future searches) It 'a matter of how CURL manages the buffer, the buffer disables the output stream with the -N option.
<code class="language-bash">
curl -s -N "URL" | grep -q Welcome
</code>
unix  shellscripting  curl  pipes  errormessage  annoyance  solution 
march 2019 by kme
unix - Use GNU screen as login "shell" - Super User
<code class="language-bash">
# if $STY is not set...
if [ -z "$STY" ]; then
exec screen -ARR
fi
</code>
unix  linux  sysadmin  screen  login  loginshell  solution 
march 2019 by kme
The #! magic, details about the shebang/hash-bang mechanism | https://www.in-ulm.de/
what's special about #!

#! was a great hack to make scripts look and feel like real executable binaries.

But, as a little summary, what's special about #!? (list mostly courtesy of David Korn)

- the interpretername must not contain blanks
- the length of the #! is much smaller than the maximum path length
- $PATH is not searched for the interpreter
- (apart from an absolute path, the #! line also accepts a relative path,
- and #!interpreter is equivalent to #!./interpreter,
- however, it's not of any practical use)
- the interpreter usually must no be a #! script again
- the handling of arguments in the #! line itself is varying
- the setuid mechanism may or may not be available for the script
- there's no way to express #!$SHELL

And why shebang? In music, '#' means sharp. So just shorten #! to sharp-bang. Or it might be derived from "shell bang". All this probably under the influence of the american slang idiom "the whole shebang" (everything, the works, everything involved in what is under consideration). See also the wiktionary, jargon dictionary or Merriam-Websters. Sometimes it's also called hash-bang, pound-bang, sha-bang/shabang, hash-exclam, or hash-pling (british, isn't it?).

According to Dennis M. Ritchie (email answer to Alex North-Keys) it seems it had no name originally.
And Doug McIllroy mentioned (TUHS mailing list), that the slang for # at Bell Labs most probably was "sharp" at the time.
bourne  bash  posix  shell  shebang  unix  linux  shellscripting  history  butwhy  explained 
february 2019 by kme
swcarpentry/windows-installer: Software Carpentry installer for Windows. | https://github.com/
Software Carpentry installer for Windows. Contribute to swcarpentry/windows-installer development by creating an account on GitHub.
workshop  windows  unix  msysgit  commandline  bash  installation  installer  script  python 
february 2019 by kme
Man pages for Git Bash on Windows 7 - Super User | https://superuser.com/
Yeah, if you want man pages by default, it's actually more prudent to do a default install of Cygwin.

You /could/ install Python, then 'pip install tldr', but that's not a good solution for a workshop.
windows  bash  git  shell  unix  workshop  howto 
february 2019 by kme
« earlier      
per page:    204080120160

Copy this bookmark:





to read