A shell is software that lets users interact with the operating system, usually by typing at a command-line.

learn more… | top users | synonyms

8
votes
11answers
10k views

how to `tail` the latest file in a directory

In shell, how can I tail the latest file created in a directory?
8
votes
9answers
2k views

Linux & Shell - Is Shell a must?

A total newbie question. Why do we need a shell in Linux? As an example when I type - find . -name xy* - I was told that the shell takes this input and calls the find command (making sure the wild ...
8
votes
4answers
1k views

How long is long for the Unix 'file' command?

When you pass a text file to the Unix file command, it might tell you something like: input.txt: UTF-8 Unicode English text, with very long lines Can somebody tell me the minimum number of ...
8
votes
4answers
1k views

Bash Shell Tutorials [closed]

What are some good bash tutorials? I would like to learn more about the bash shells commands and how to use them.
8
votes
6answers
6k views

unix - split a huge .gz file by line

I'm sure someone has had the below need, what is a quick way of splitting a huge .gz file by line? The underlying text file has 120million rows. I don't have enough disk space to gunzip the entire ...
8
votes
2answers
14k views

Bash not loading '.profile' in new session on Linux

I'm setting up a new Linux machine I got from our IT dept, and noticed .profile is not loaded when I start a new terminal session. The current shell is Bash, though I changed it from the default sh it ...
8
votes
5answers
3k views

Will a Mac help me learn Linux?

I worked with a Mac last week for the first time ever. I noticed that the shell is very similar to Linux. I normally develop on a Windows machine and tend to be a noob at all things Linux. Will a Mac ...
8
votes
4answers
5k views

Linux : To monitor a Service and restart if stopped?

Actually I'm not so sure whether i should use Shell Scripts, or if there some ways already. But whatever approach we use, i would like to keep a Service running all the time. Let's say iptables as an ...
8
votes
6answers
5k views

Clear stdin before reading

I have the following bash script: # do some time consuming task here read -p "Give me some input: " input Now as you might have guessed, if a user presses some random keys during the "time ...
8
votes
3answers
829 views

`which python` points to the python I want, but `python` runs the wrong version

I want to use python24 provided by ports, so I've installed it, and python_select -s shows that the version I want is indeed selected. Running which python gives /opt/local/bin/python, and running ...
8
votes
1answer
13k views

How can I kill Firefox by console?

I know I can type: ps -A | grep firefox I get something like: 6818 ? 00:04:23 firefox Now I can kill it by means of: kill -9 6818 How can it be done in one command and how can I make ...
8
votes
3answers
4k views

Mouse cursor in Terminal?

I use Mac OS X Terminal.app. But the answer to this would probably apply to any typical UNIX-ish terminal emulator in a graphical environment. Question -- what do I do to: Use my mouse cursor to ...
8
votes
3answers
31k views

How to display current path in command prompt in linux's sh (not bash)?

I would like to display current path in sh prompt (not bash shell), which currently just shows "#", I tried with introducing this env PS1="$(whoami)@$(hostname):$(pwd)" and set ...
8
votes
2answers
485 views

Can I keep . and .. out of .* expansion?

I often find it annoying (or worse) when I type command .* in bash and the command applies to the parent directory and current directory. Is there some shell option or other configuration I can ...
8
votes
2answers
2k views

Writing shell scripts that will run on any shell (using multiple shebang lines?)

I've just started getting deeper into shell scripting, and I've always just thrown my script in a file, marked it chmod +x and then done /path/to/script.sh and let whatever interpreter is the default ...
8
votes
2answers
6k views

Indicating end of Standard Input

How does one indicate that one has finished entering test in stdin? For example, let's say that I wish to encrypt 'blue' using MD5 (I know MD5 is unsecure, but just for this example). I tried user$ ...
8
votes
2answers
834 views

Making bash TAB completion more like cmd.exe [duplicate]

I wondered if theres a way to do rotational style completion in bash similar to the behavoir on cmd.exe, I've found it speeds me up in regard to entering commands
8
votes
4answers
9k views

UNIX shell scripting: how to recursively move files up one directory?

I have a large number of small files, f, arranged in a directory structure like so: /A/B/C/f There are 11 directories at the level of A, each with about 100 directories at the level of B, each with ...
8
votes
3answers
987 views

How can I keep the color when I run the external command inside vim?

For example, for the command ls --color displays colorful results when being executed in the shell. However, when I call :!ls --color inside vim, all color information is gone. What should I do to ...
8
votes
8answers
772 views

Per-directory bash/zsh history log files

I find I do a lot of work on a project in a set directory. Sometimes — a few months down the track — I need to redo something on that project but I can't remember what I did. I use ...
8
votes
3answers
361 views

Is it possible to configure the way bash completes directory names?

I'd like to instruct bash to use a special method to perform completion on certain directory names. For example, bash would call a program of mine to perform completion if a path starts with "$$", and ...
8
votes
3answers
8k views

Run a GUI app on remote computer from SSH

I want to run a GUI application on my Ubuntu computer, but it should started by a shell script on my Debian server trought SSH. Is this possible?
8
votes
3answers
160 views

Windows 7 coming from Linux/Unix?

I've got a Windows 7 box going for my job, and most high-level computing experience is coming from shell environments in Linux. I'm completely lost in the Windows shell, and when I try to use a GUI ...
8
votes
3answers
402 views

Tabbed terminal that connects to a GNU Screen session?

I use the session feature of screen extensively. For example, I'll start a screen session for "project1" as "screen -S project1", and then when I need to reconnect I use "screen -d -r project1". ...
7
votes
7answers
14k views

How can I list only non-empty files using ls?

How can I list (using ls) all files that are not empty (size > 0) using linux?
7
votes
6answers
4k views

Best practices to alias the rm command and make it safer

Some time ago I erroneously deleted my home folder because I ran a rm -rf * on the wrong terminal, whose working directory was the home folder! I wish I had an alias for the rm command, but it was ...
7
votes
5answers
8k views

Linux command to find files changed in last n seconds.

I would like a Linux command to find files changed in last n seconds. Is there a shell script or other tool that I can run from command line interface or gui?
7
votes
8answers
3k views

Ending a process in unix instead of interrupting it

At the unix command line if i press Ctrl-C,that does not end a process but rather interrupts it and i return to the shell prompt. So,i have the following two questions: 1.Is there a way i can see the ...
7
votes
2answers
714 views

How do I delete a file named “-p” from bash?

How do I delete a file named -p in bash? Trying rm "-p" complains that -p is not a valid argument.
7
votes
4answers
280 views

What to use for Shell Access? [closed]

I just purchased a virtual dedicated server-plan that comes with shell access. It's been a while since I've actually used shell access remotely, so I'm a bit behind the times. Years ago I used PuTTY, ...
7
votes
3answers
9k views

How to join files on the command line without creating temp files?

I have two files in a Linux / Bash environment: # Example data $ cat abc 2 a 1 b 3 c $ cat bcd 5 c 2 b 1 d I'm trying to join the two files on the first column. ...
7
votes
8answers
15k views

How to find out the top space-consuming directories or files?

My disk is running out of space: $ df -h Filesystem Size Used Avail Use% Mounted on ... /dev/sda7 803G 715G 48G 95% /home I'd like to go through the whole home directory and find ...
7
votes
1answer
8k views

When using “gzip --decompress”, the result is “gzip: MYFILE.zip: unknown suffix — ignored” on Windows

In Windows PowerShell (if it matters), I would like to decompress a zip file with gzip with the argument --decompress, but unfortunately it doesn't work. Please look at the screenshot below. gzip ...
7
votes
4answers
16k views

echo newline character not working in bash

I have bash script which has lots of echo statements and also I aliased echo to echo -e both in .bash_profile and .bashrc, so that new lines are printed properly for a statement like echo ...
7
votes
4answers
460 views

Documenting Unix commands on the command line

I would like to append both the last command and the output of the last command to a text file for the purpose of a tutorial. For example: After I do an ls in my home directory I see this on the ...
7
votes
5answers
7k views

How can I sort all files by size in a directory?

How can I display the files in a unix directory sorted by their human readable size, going from largest to smallest? I tried du -h | sort -V -k 1 but it does not seem to work.
7
votes
2answers
2k views

Smart tab completion (for directories)?

Are there shell versions that have a more intelligent tab completion? I'd like to be able to type cd foo-<TAB> Then it would show me the possible completions along with numbers that I can ...
7
votes
1answer
9k views

run or send a command to a tmux pane in a running tmux session

I want to write a shell script which will attach to a named tmux session, select a window (or pane) in that session and run a command in that selected window (or pane). How do I do this from a bash ...
7
votes
1answer
12k views

Retrieve Linux command line history by date

I want to see what I typed on my bash command line on a certain day a week ago. Is there a way to retrieve command line history? Something like below, perhaps? > history --include-date | grep ...
7
votes
3answers
485 views

Why I have to type “./” always before an executable to execute it in Linux?

When I compile e.g. x.c by: GCC x.c -o x To execute result I have to write: ./x And just typing: x Fails with this message: x: command not found This means Linux does not search current ...
7
votes
3answers
967 views

Is there a shell which supports fuzzy completion as in Sublime Text?

I'm using bash and I was wondering if there is any plugin in bash or other shell which allows me to do this cat tfnislong.txt + [tab] completes to cat ThisFileNameIsSoLong.txt just like tab completion ...
7
votes
3answers
2k views

How to run Vim command from the shell?

This might be a dumb question, but bear with me. I'm automating some of the usual stuff I do when setting up a new work environment, and would like to automate the Vim command :BundleInstall (for ...
7
votes
2answers
103 views

Is it possible to modify bash to run one command through another (say a python script)?

I was wondering if it is possible to modify bash such that when I type command --arg1 what actually happens is ~/prerun.py command --arg1 (prerun.py would handle starting command --arg1 itself) ...
7
votes
1answer
2k views

ZSH tab completion of git commands is very slow. How can I turn it off?

If I type: rm <TAB> I'll see possible completions almost instantly. However, if I type: git rm <TAB> It'll hang for several seconds if it's in a git repo, or fail to show any ...
7
votes
4answers
9k views

How do I log all UNIX shell commands submitted by all users?

Is there an elegant way to log every command submitted in all shells on a machine? This is in the context of an infrequently-used Ubuntu server, of which I am the only human user. (There are several ...
7
votes
4answers
5k views

Get the parent directory for a file

I want to get just the name of the parent directory for a file. Example: When I have path=/a/b/c/d/file, I want only d and not /a/b/c/d (which I get from dirname $path) as output. Is there any ...
7
votes
3answers
978 views

PDF reader for the CLI

I'm looking for a PDF reader that I can use over SSH in a terminal, and have it running in screen. Does such a thing exist? Ideally I'd like at least a less-esque pager but with some PDF formatting, ...
7
votes
2answers
266 views

Why can bash cd to //?

In bash if you cd to // your pwd will be //, but if you cd to / or ///+ your pwd will be /. Is there a reason for this or is it just a weird bug? I have tried this in osx and ubuntu.
7
votes
2answers
6k views

How do I create a shortcut that opens Cygwin bash shell on a directory of my choosing (UNC especially)?

Given a standard installation of Cygwin for Windows XP, I would like to create a standard Explorer shortcut that opens a bash shell already open on a directory of my choosing. The directory is a UNC ...
7
votes
1answer
2k views

Shell script to find all types of files in a directory with their count

I want to write a shell script or alias to find the number of different types of files in a directory. For example, sample output of script should be: *.h 20 *.c 40 *.cpp 10 Makefile 3