Site icon AranaCorp

Launch a Profile file at Linux startup

In this tutorial, we’ll look at how to create and launch a Profile file at startup on a Linux machine, such as your Raspberry Pi, in order to configure and personalize your user account. When you regularly use your Linux computer, it can be useful to load a profile at start-up, so that you have an environment that suits you and can follow you from one machine to another.

N.B.: To obtain the same functionality as a .profile file, you can create a file that you launch at system startup (in the rc.local file or using crontab) with the source command .

What is a profile file?

As mentioned in the introduction, a profile file is launched when the machine starts up. There are configuration files specific to the system (OS, hardware) which will be loaded for all users, and configuration files specific to each user account which will be launched on login and enable aliases, functions, access paths, etc. to be configured.

Where can I find the profile file?

The most common profile file is hidden and located in the .profile root. If it’s a file you’ve created and run at startup or manually, you can save it wherever you like.

To find it, you can use the following command to display the hidden files on your system

ls -a
ou
ls -al

Here are some configuration files that load on startup

What do I put in the profile file?

The language used in the profile file is bash. It must therefore be adapted to the shell used.

When working with Linux, you often have to deal with the terminal and the command line. Aliases can be used to shorten command lines.

alias <name>='command1 arg1 arg2; command2'

N.B.: there is no space around the “=”. You can use ” ; “, ” && ” or ” | ” to put several commands in a row.

alias ll='ls -l'

You can find the list of aliases by typing the command alias without arguments

some practical applications

alias update='sudo apt-get update &amp;&amp; sudo apt-get upgrade'
alias histg='history | grep' # "histg cd" list all previous commands containing cd
alias aptclean='sudo apt-get -y autoremove &amp;&amp; sudo apt-get clean'
alias syslog='cat /var/log/syslog'

Once created, this file can follow you from one machine to another, enabling you to find your environment again.

functions are like aliases with command sequences that can be more complex

cdl(){
    cd "$@";
    ls -al;
}

A bit like aliases, you can create environment variables and give names to your access paths, for example

export workdir="/home/user/work/"

to see all the exports: export -p

Sources

Exit mobile version