Commands tagged System Administration (11)

  • The empty file /forcefsck causes the file system check fsck to be run next time you boot up, after which it will be removed. This works too: sudo >/forcefsck


    38
    sudo touch /forcefsck
    johnraff · 2009-10-29 17:04:47 17
  • List all file opened by a particular command based on it's command name. Show Sample Output


    25
    lsof -c dhcpd
    d4n3sh · 2009-04-17 07:18:38 11
  • Lis all files opened by a particular process id. "PID" Show Sample Output


    6
    lsof -p 15857
    d4n3sh · 2009-04-17 07:16:03 5
  • This command will log the output of your simple cronjobs to syslog, and syslog will take it from there. Works great for monitoring scripts which only produce simple output. Advantages: * This can be used by regular users, without modifying system files like /etc/syslog.conf * Reduce cron spam to root@localhost (Please stop spaming the sysadmins) * Uses common tools like syslog (and logrotate) so that you don't need to maintain yet another krufty logfile. * Still ensures that the output is logged somewhere, for posterity. Perhaps it's stored the secure, central syslog server, for example. * Seems to work fine on Ubuntu, CentOS, FreeBSD & MacOSX Show Sample Output


    6
    */5 * * * * root /usr/local/nagios/sbin/nsca_check_disk 2>&1 |/usr/bin/logger -t nsca_check_disk
    StefanLasiewski · 2010-07-02 00:47:05 6
  • Many times I give the same commands in loop to find informations about a file. I use this as an alias to summarize that informations in a single command. Now with variables! :D Show Sample Output


    2
    fileinfo() { RPMQF=$(rpm -qf $1); RPMQL=$(rpm -ql $RPMQF);echo "man page:";whatis $(basename $1); echo "Services:"; echo -e "$RPMQL\n"|grep -P "\.service";echo "Config files:";rpm -qc $RPMQF;echo "Provided by:" $RPMQF; }
    nnsense · 2015-05-11 16:46:01 13

  • 1
    tune2fs -c -1 -i 0 /dev/VG0/data
    christian773 · 2010-05-29 08:20:35 3
  • if you need to install cron jobs in a given time range. Show Sample Output


    1
    H=$(until ([ $i -le 6 -a $i -gt 0 -o $i -le 23 -a $i -gt 21 ] ); do i=$(date +%N | cut -c8-10); done ; echo $i) ; M=$(until [ $i -le 59 ]; do i=$(date +%N | cut -c8-10); done ; echo $i) ; echo $M $H \* \* \* backup-rsync-push.sh
    christian773 · 2010-05-29 08:42:43 6
  • I use this as an alias to get all .service files related a single installed file/conf (if it has services, of course). For rpm based systems ;) Show Sample Output


    1
    qf2s() { rpm -ql $(rpm -qf $1)|grep -P "\.service"; }
    nnsense · 2015-05-11 16:32:16 9
  • Change run control links from start "S" to stop "K" (kill) for whatever run levels in curly braces for a service called "myservice". NEWFN variable is for the new filename stored in the in-line shell. Use different list of run levels (rc*.d, rc{1,3,5}.d, etc.) and/or swap S with K in the command to change function of run control links. Show Sample Output


    0
    sudo find /etc/rc{1..5}.d -name S99myservice -type l -exec sh -c 'NEWFN=`echo {} | sed 's/S99/K99/'` ; mv -v {} $NEWFN' \;
    zoomgarden · 2010-01-03 00:56:57 4
  • date MMDDhhmmYYYY date MMDDhhmm # example 27.12.1975 08:00 date 122708001975 Show Sample Output


    -1
    date MMDDhhmmYYYY
    christian773 · 2010-05-29 08:26:13 3

  • -3
    tune2fs -l $(df -P / | tail -n1 | cut -d' ' -f1 ) | grep 'Filesystem created:'
    christian773 · 2010-05-29 08:15:25 4

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

Transfer SSH public key to another machine in one step
This command sequence allows simple setup of (gasp!) password-less SSH logins. Be careful, as if you already have an SSH keypair in your ~/.ssh directory on the local machine, there is a possibility ssh-keygen may overwrite them. ssh-copy-id copies the public key to the remote host and appends it to the remote account's ~/.ssh/authorized_keys file. When trying ssh, if you used no passphrase for your key, the remote shell appears soon after invoking ssh user@host.

Write comments to your history.
A null operation with the name 'comment', allowing comments to be written to HISTFILE. Prepending '#' to a command will *not* write the command to the history file, although it will be available for the current session, thus '#' is not useful for keeping track of comments past the current session.

Read aloud a text file in Mac OS X

Count number of files in a directory
Just want to post a Perl alternative. Does not count hidden files ('.' ones).

Download all PDFs from an authenificated website
Replace *** with the appropiate values

Multi-thread any command
For instance: $ find . -type f -name '*.wav' -print0 |xargs -0 -P 3 -n 1 flac -V8 will encode all .wav files into FLAC in parallel. Explanation of xargs flags: -P [max-procs]: Max number of invocations to run at once. Set to 0 to run all at once [potentially dangerous re: excessive RAM usage]. -n [max-args]: Max number of arguments from the list to send to each invocation. -0: Stdin is a null-terminated list. I use xargs to build parallel-processing frameworks into my scripts like the one here: http://pastebin.com/1GvcifYa

disable caps lock
a quick one-line way to disable caps lock while running X.

Get a qrcode for a given string

Setting reserved blocks percentage to 1%
According to tune2fs manual, reserved blocks are designed to keep your system from failing when you run out of space. Its reserves space for privileged processes such as daemons (like syslogd, for ex.) and other root level processes; also the reserved space can prevent the filesystem from fragmenting as it fills up. By default this is 5% regardless of the size of the partition. http://www.ducea.com/2008/03/04/ext3-reserved-blocks-percentage/

Show apps that use internet connection at the moment.
show only the name of the apps that are using internet


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: