Find the answer to your Linux question:
Results 1 to 2 of 2
How would I put a set of commands in a file. Example : I want to be able to get the output of ls -all by typing 'list' Basically I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2007
    Posts
    19

    Commands to File help


    How would I put a set of commands in a file.

    Example : I want to be able to get the output of ls -all by typing 'list'

    Basically I need to save the command into a file, so when the i type the name of the file, it will execute the command, does anyone know how to do this?

  2. #2
    Linux Newbie
    Join Date
    Feb 2007
    Location
    San Antonio, TX
    Posts
    114
    to answer your question, you would do a couple of steps
    1 - put the line "ls -all" in an empty file called "list" using something like vi or pico
    2 - add execute permissions for the file using "chmod +x list"
    3 - put the file "list" in a typical spot for executables, such as /home/<user>/bin/
    4 - add this location to your path (if it's not there already) by:
    a - open ~/.bashrc using something like vi or pico
    b - add the lines:
    Code:
    PATH=${PATH}:/home/<user>/bin
    export PATH
    (replacing <user> with your user name naturally)
    c - source your bash:
    Code:
    source ~/.bashrc

    but your example could be accomplished much easier by just putting
    Code:
    alias list='ls -all'
    in your .bashrc and sourcing it with the above command

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •