User Tools

Site Tools


info:linuxcommands

Linux Commands

alternatives

"Maintain symbolic links determining default commands" (manages links in the /etc/alternatives directory). The command is called update-alternatives on Debian systems, and may be available as alternatives on other systems (e.g. RHEL).

There is a GUI frontend to update-alternatives called galternatives.

bash

  • Ctrl+R: reverse search; enter to accept, Ctrl+R to go to the previous match, tab to select the current match for editing

Debugging

Turn Vim into a bash IDE

Compiling programs from source

When Fred compiles an application from source, he creates a file called DoConfigure so that he can remember what options he used. I was thinking something like config-sam.sh (chmoded +x so that it stops the shell completion from filling out "./configure").

'less' options for paging like git

By default, git uses less for paging, and it sets the LESS environment variable to FRSX 1), which is equivalent to calling less -FRSX. To get similar behavior from, for instance, grep or ls, one would want to specify the option --color=always to force them to pass the color escape sequences through the pipe to less.

less opens binaries (with help from lesspipe)

I just noticed it in my .bashrc. lesspipe lets you type things like this:

less foo.tar.gz  #list the contents of the archive
less bar.png     #maybe do something useful if ImageMagick is installed?

Anyway, this works by default in Ubuntu. man lesspipe gives more details, and lists file types:

*.arj
*.tar.bz2
*.bz
*.bz2
*.deb, *.udeb
*.doc
*.gif, *.jpeg, *.jpg, *.pcd, *.png, *.tga, *.tiff, *.tif
*.iso, *.raw, *.bin
*.lha, *.lzh
*.pdf
*.rar, *.r[0-9][0-9]
*.rpm
*.tar.gz, *.tgz, *.tar.z, *.tar.dz
*.gz, *.z, *.dz
*.tar
*.jar, *.war, *.xpi, *.zip
*.zoo

Mount

Change mode/ownership when mounting Samba shares

Finally found at http://linux.die.net/man/8/mount.cifs:

  • file_mode=arg e.g. file_mode=0600
  • dir_mode=arg e.g. dir_mode=0700
  • uid=arg
  • gid=arg

Also see https://help.ubuntu.com/community/MountWindowsSharesPermanently.

Mount an ISO file

mount -o loop -t iso9660 file.iso /mnt/test

Mount existing LVM

http://www.linuxquestions.org/questions/linux-software-2/how-do-i-mount-existing-fedora-lvm-after-new-kubuntu-install-633547/

Ubuntu needs the lvm2 package.

Here are some commands, including an example mount command:

pvscan
vgscan
vgchange -a y
mount -t ext3 /dev/VolGroup00/LogVol00 /media/mylvm

RPM

  • q: query packages
    • a: all packages
    • i: display package information
    • l: list files in package
    • Finding what package a file belongs to: rpm -q --whatprovides /path/to/file

Examples:

Find a package:

rpm -qa | grep SOMETHING

Information about a package:

rpm -qi PACKAGE_NAME
rpm -ql PACKAGE_NAME

Install a package (verbose, progress bar):

rpm -Uhiv RPM_FILE

SSH

See SSH.

GNU tar

The --exclude option comes before the path but after the filename, if specified. For example:

tar cvfj foo.tar.bz2 --exclude /home/foo/bar /home/foo

Ubuntu

Change timezone:

dpkg-reconfigure tzdata

lsb_release for distribution information

lsb_release -rd
lsb_release -a

For example:

Description:	Ubuntu 8.10
Release:	8.10

Find text in files (current directory)

Find text in files, ignore binary files; works with spaces in path by separating arguments with '\0' instead of whitespace.

Variations:

find . -print0 | xargs -0 grep --binary-files=without-match 'TEXT'
find . -print0 | xargs -0 grep --binary-files=without-match --color=yes 'TEXT'
find . -print0 | xargs -0 grep --binary-files=without-match --color=yes 'TEXT' | less -r
find . -print0 | xargs -0 grep --binary-files=without-match --color=yes 'TEXT' | grep -v '/.svn/'

Hardware Info

No hwinfo in the repositories, but lshw (and lshw-gui) are available in the EPEL repository, for RHEL5 anyway.

Ethernet Speed

To see negotiated ethernet speed:

ethtool eth0

or

dmesg | grep eth0

Both should show if you have a 1000 Mbps / gigabit connection. mii-tool won't show gigabit.

Use 'perl' like 'sed'

Perl can be used for one-liners like a more powerful sed. For example:

perl -p -i.bak -e 's/; / \&\& /g' <INPUT FILE>

The -i makes it make the changes in-place. Remove the '.bak' to forgo making a backup.

info/linuxcommands.txt · Last modified: 2010-12-09 20:09 by sam